Say you want to build an app that changes the Bean's LED based on the sentiment of a tweet. Normally, you'd have to go through the process of writing software that can speak to both Twitter and the Bean. If you use Node-RED, you can avoid having to write that software since it understands how to communicate with both.
In this tutorial, you'll build a Node-RED flow that connects your tweet's sentiment to the Bean's LED color. If there are a lot of happy tweets, the color of the LED will be more green and if they are angry it will be more red.
* Windows or OSX computer
What is Node-RED?
Node-RED is a visual programming interface for the Internet of things. If you haven’t used Node-RED with the LightBlue Bean before, you need to set it up before following this tutorial.
This is what the Node-RED flow for the project looks like:
Tweets: Uses the Twitter API to monitor tweets to or from a specified user or hashtag.
Test nodes: Nodes that inject a happy, angry or neutral string to test that it works without having to wait for tweets.
Sentiment: Measures the sentiment of any string passed to it and scales it from -5 to 5, going from angry/sad to happy.
Sentiment to LED val: Takes the average sentiment value of the five most recent tweets and translates it to an RGB value. Happy tweets give more green, and angry/sad tweets make the color more red. Neutral tweets lower the intensity of the LED.
Bean LED: Sets the Bean’s LED to the given RGB value.
Copy the JSON data below to your clipboard:
ArduinoStep 2: Start Node-RED server
Open your terminal. Navigate to your Node-RED folder and type
http://localhost:1880/ in your browser. Click the menu in the top right corner and choose
import > clipboard
Double click the Bean LED node and click on the pen to edit the Bean settings. Update the name to be the name of your Bean. It is important you write the exact name as it’s the only way for Node-RED to find and connect to the correct Bean.
Double click the tweet node and choose “add new Twitter credentials” to connect to the Twitter account you want to use. Choose what you want to monitor: all public tweets, the tweets of who you follow, tweets of specific users or your direct messages.
Click deploy in the top right corner and you’re done!
Why not make this a full-fledged nice-looking mood light? Check out our mood light tutorial on how to connect your LightBlue Bean to a NeoPixel ring and putting it in a light globe. Working with social media management has never been as easy!
Having trouble with this guide? Reach out to BeanTalk to get directed feedback from our developers and community!