Project tutorial
Twitter Sentiment Gadget

Twitter Sentiment Gadget © CC BY

How is your twitter feed feeling? Happy or Sad? Lets Find out!

  • 1,352 views
  • 0 comments
  • 2 respects

Components and supplies

Apps and online services

About this project

Introduction to Node-Red

Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.

Node-Red is a browser based tool to let you quickly and easily construct your own logic of handling various IoT devices, including subscribing the MQTT messages, listening to HTTP requests, reading and writing to Databases, publishing to MQTT brokers and responding to HTTP requests. It also allows you to define specific functions written in JavaScript to provide complex logic operations, while using a visual, easy to use, drag-and-drop user interface to link different components and logic together.

Node-Red is a very light weighted run time built on top of Node.js, taking full advantage of its event-driven, non-blocking model of operation.

Watch the video here

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

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 term
  • all tweets by specific users
  • direct messages received by the authenticated user

Use 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

A function block where you can write code to do more interesting things.

The message is passed in as a JavaScript object called msg .

By convention it will have a msg.payload property containing the body of the message.

Our function Node Looks something like this.

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.

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.

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.

Code

Schematics

Comments

Similar projects you might like

LED Displayed Twitter Sentiment Analysis

Project tutorial by Andrew Steinheiser

  • 1,269 views
  • 1 comment
  • 3 respects

Location Display With Idiotware Shield

Project tutorial by 3 developers

  • 1,608 views
  • 0 comments
  • 3 respects

Smart IoT Postbox with the idIoTware Shield

Project tutorial by Ravi Parmar and Rupin Chheda

  • 4,985 views
  • 4 comments
  • 14 respects

Bitcoin Price Updates

Project tutorial by Rupin Chheda and IdiotWare Team

  • 2,372 views
  • 1 comment
  • 11 respects

Lights On/Off using Twitter

Project showcase by Kaustubh Agarwal

  • 4,287 views
  • 0 comments
  • 15 respects
Add projectSign up / Login