Using the sentiment node in Node-Red, we are analysing a twitter feed to find out if the sentiment if the feed is happy, sad or neutral.
This instructable uses the Idiotware Shield as one of its component.
The Idiotware Shield is a learning platform for quickly bringing to life hundreds of Arduino projects, whether you’re a novice or expert. The Idiotware Shield is the Swiss Army Knife of Arduino shields, with plenty of integrated inputs and outputs and options for connectivity and expansion.
This instructable is part of a series of projects in the list for "50 Days of Simplifying Arduino"
For every day of this crowdfunding campaign, we’re going to publish a new project showing how the Idiotware Shield simplifies creating awesome Arduino projects.
Our campaign can be supported here https://www.crowdsupply.com/curiosity-gym/idiotwar...
Step 1: Introduction to Node-Red
Node-Red allows you to create flows using drag and drop functionality to connect together inputs, outputs and web services to create an application. We are using a Raspberry Pi to run Node Red. On instructions to install Node-Red on the Raspberry Pi, follow this link https://nodered.org/docs/hardware/raspberrypi
A Node-Red node is a function block which consists of at least one input, some internal logic, and zero or more output. Data is usually carried via the msg.payload though it can be carried by other properties under msg. A node can also be configured to access to certain resources such as file from the file system, a database, MQTT messages, or the local hardware I/O, for example, I/O pins on a Raspberry Pi. The MQTT nodes are for talking with the MQTT brokers. The broker we have used is iot.eclipse.org
Step 2: Connecting Node-Red to Twitter
Create the following flow in Node-Red.
1) Twitter input node.
Can be used to search either: the public or a user's stream for tweets containing the configured search termall tweets by specific usersdirect messages received by the authenticated userUse space for and and comma , for or when searching for multiple terms. Sets the msg.topic to tweets/ and then appends the senders screen name. Sets msg.location to the tweeters location if known. Sets msg.tweet to the full tweet object.
2) Sentiment Node
Analyses the msg.payload and adds a msg.sentiment object that contains the resulting AFINN-111 sentiment score as msg.sentiment.score . A score greater than zero is positive and less than zero is negative. The score typically ranges from -5 to +5, but can go higher and lower. See the Sentiment docs here.
3) Function Node
4) MQTT Node
Connects to a MQTT broker and publishes messages. The topic used can be configured in the node or, if left blank, can be set by msg.topic . Likewise the QoS and retain values can be configured in the node or, if left blank, set by msg.qos and msg.retain respectively. By default, messages are published at QoS 0 with the retain flag set to false. If msg.payload contains an object it will be converted to JSON before being sent. Here is how our MQTT Node Configuration Looks Like. The Topic Field is case sensitive and should be customised, because devices subscribed to same topic (/Idiotware/twitterpetcube) on same server (iot.eclipse.org) will recieve messages published from any device that sends it to the same server and topic.
To test the flow, hit the Deploy button on the upper Right Corner. The debug nodes help show the data sent by the sentiment and function nodes.
If all goes well, you should see the debug console ( right side, tab on top) display a number whenever your tweet to the handle configured in the Twitter Node.
Step 3: Settings for ESP-Link
The ESP-Link firmware is standard for the Idiotware Shield. This firmware has settings to configure MQTT. As show below the server is set to iot.eclipse.org and topic updates received from MQTT will be available on the Arduino with the help of the Idiotware Shield.
Step 4: Representing the Sentiment Value on the Idiotware Shield
The sentiment value is sent to MQTT broker iot.eclipse.org by Node Red Flow. Once this is received by the broker, it sends it downstream to all subscriber nodes which are listening for data on a specific topic.
In our case, the topic /Idiotware/twitterpetcube is subscribed by the Idiotware Shield and is the recipient of the data published on that topic.
There is a section in the code that can be changed to a specific, custom topic to subscribe to. Once this topic is changed to what has been set in Node-Red, the sentiment value will be received on the Idiotware Shield, and the code will choose an appropriate graphic to show on the OLED.
Step 5: Download Code and Schematics
Code can be accessed here
Schematics can be browsed here
Support our Crowdfunding campaign here