I wanted to make my desk a little festive this Christmas season with a quick project. Two LEDs create the simple circuitry that looked Christmas appropriate but connecting it to Twitter allows me to watch Christmas spirit across the globe!
This project was made very quickly using the nio Platform, a Raspberry Pi, and some quick crafting. Full disclosure, I work for niolabs, a software company that allows you to design this kind of edge logic using our platform and tools.
Setting up nioI have gone through this before on other projects but after signing up for a trial account at https://account.n.io, you can obtain the nio binary which will run on the Raspberry Pi. I prepared the Pi to run nio with the following steps:
Install a few packages with the apt package manager
sudo apt install python3-dev libffi-dev libssl-dev git
Install the pip package manager for python
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py —-user
echo 'export PATH=/home/pi/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Create a python virtual environment to run this project
pip3 install virtualenv --user
virtualenv env
source env/bin/activate
Install the nio binary that I obtained with my trial account (make sure you copy the whl file to the Pi)
pip install nio_lite*.whl
Finally I can access the nio System Designer at http://app.n.io to create a system. Opening the newly created systems 'edit' menu will give me the hostname and token credentials for the final step which is running nio
nio new Christmas -t https://github.com/tlugger/christmas_edge.git --pubkeeper-hostname <your-pk-hostname> --pubkeeper-token <your-pk-token> --no-ssl
cd Christmas
niod
With this, nio is now running on the Raspberry Pi zero and will attempt to poll twitter for #Christmas tweets. The final step is to connect to this instance in the nio System Designer and configure our Twitter block with credentials from https://apps.twitter.com/.
Service LogicThe service running on the Raspberry Pi is fairly simple:
Signals generated by the Twitter block will flow from top to bottom though each block. Each block will add to or modify the signals in some way. The pseudo-logic here is get tweets from twitter, split any combined tweets into separate signals per tweet, grab the 'text' attribute from the signal which contains the content of the tweet, increase our count based on this tweet, format our cumulative count, text, and color for the LED, publish this signal to the Dashboard, and finally control the LEDs through GPIO pins on the Raspberry PI.
Creating the DashboardMy dashboard acts as a monitor for all of my personal nio projects. I previously used this to track the status of my connected plant with automated irrigation here. Another card is created for this project to watch the live count, see the tweet that increased the count, and of course see the color of my light as it flickers
Watch my Christmas count increase at https://cilantr.io! All code and schematics are provided here as well if you want to make your own. Feel free to reach out if you want help getting started!
Comments