Node-Red
Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways. Built upon Node-js Node Red allows browser based flow editing. What does this mean? Node Red is a transformation layer. At the heart of it what node red does is it allows you to transform data from one form to another. Have you got some JSON data and want to transform it into XML data. Have you been wanting to make a service which looks for a hashtag and then text’s your mobile phone when it’s seen. Node Red allows you to connect things, in interesting ways. A good way to think of it is as the Lego of software development. It allows even non-technical users perform interesting conversions without having to write any software. The Node-Red interface has been pre-configured to start automatically with the machine and no additional configuration should be necessary for this service.
To access the node-red control interface first go to http://datatoolkit.org.uk:1880/ in your browser. When you have loaded this up you will be presented with a screen as below:
For more information on Node-Red please visit:
Our first Node-Red flow
So we’ve got as far as the interface. While the interface may look scary to begin with the Node-Red interface is actually very simple. We generate flows by dragging and dropping Input, Modification and Output blocks from the left sidebar into our workspace in the centre.
In our first flow we will be generating a system which will search Twitter for a user’s posts and when that user posts it will send us a text message on our mobile phone. To complete this experiment we will need to have:
-
A Twitter account — https://twitter.com/signup
- a Twilio account — https://www.twilio.com/try-twilio
Both of these accounts are free to signup for and are awesome services. Head on over to twitter and Twilio via the above links and get your account set up. In Twilio you will need to register your mobile phone before you are able to send any messages to it. This is a limitation of the free trial account.
Once the accounts are set up you can begin to generate the flow. This flow is super simple. We will start by dragging out a Twitter input node. You know it’s an input node as it has a square box on the right of the node. When that’s in our workspace we will then drag a Twilio output node (square is on the left). You can then click and drag from the square on the Twitter node to the square on the Twilio node to generate a link between them. Once the nodes are connected we need to insert parameters into the nodes. To do this double click the node and it should pop up a box as below:
In the box you will first need to authorise Node-Red to access your twitter account. To do this click the pencil icon on the side of the Log-in box and follow the instructions given. Once you are authorised with your twitter account set the node to search for tweets from a specific user. Finally you can give it a name which is visible in the node-red interface.
The Twilio node is a bit harder to set up but don’t let that put you off. The details you will require from the Twilio site are:
-
Your Twilio outgoing number
-
Your Account SID — a long string of numbers and letters
-
Your Authorisation Token — another long string of numbers and letters
Armed with these pieces of information you’re all set to configure your Node-Red flow! Select to use local credentials and click the pencil icon to enter your Twilio details.
Here you need to enter your Account SID, From telephone number (The number Twilio gave you – prefixed with +44 and replace the first 0), and your Authorisation token. You can give this a name too.
Once these details are in you can set a recipient of the text messages that Node-Red will receive, if this is a free trial Twilio account this MUST be the phone number you registered with Twilio as this will be the only phone the service will send to.
Once the nodes are connected and properties set we are done. All we need to do now is deploy the flow to the broker, to do this we click the large red deploy button and if this is successful a dropdown saying success will be visible as below:
Once the flow is deployed it is time to test it, get the specified user to send a tweet or wait until their next tweet. When this happens there may be a 1 minute delay while twitter updates it’s indexes but you should shortly receive a text message on your phone. If nothing appears make sure all the information provided is correct and you are using the correct phone numbers. There you go you have generated your first flow. To stop the flow click on the link between the nodes and press the delete key on the keyboard and then re-deploy. This will stop the flow from sending text messages indefinitely. There are many more things you can do with Node-Red such as intercepting messages from MQTT or news stories online. We have only scratched the surface of what can be achieved so the best way to learn is to play. All the documentation for Node-Red is available at:
Good luck and have fun with this brilliant tool!