Tweeting with Node-RED via a mqtt broker

Having had a wonderful weekend at Wuthering Bytes, I decided to try and install the fabulous Node:RED tool and try to use it with mqtt to tweet the light level.

Firstly Node-RED depends on node.js, so I installed node.js via Chris Lea’s ppa – he seems like the right sort of person to package up the current stable version and keep it up to date. The instructions here: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint worked fine except that I omitted the specific version string and apt-get automatically chose the more recent version. I got v0.10.18-1chl1~raring1 which is bang up to date. If I’d used the package manager without adding Chris’s repository then I would have got v0.6.19~dfsg1-5ubuntu1 which is almost certainly too old for node-RED.

Then to install Node-RED itself – the installation page here: http://nodered.org/docs/getting-started/installation.html is very well written so I won’t duplicate it here. Helpfully, the example of installing additional nodes is for twitter, so I went ahead and did a

 npm install ntwitter oauth

then I could just get going with

node red.js

and voila! my browser at localhost:1880 now displays a Node-RED screen.

Next up – install a mqtt broker – seems like mosquitto is a good one, but again the official repositories lag way behind the code, the ubuntu one is at 0.15 and the mosquitto provided one (http://mosquitto.org/download/) is at 1.2! I started it with a

mosquitto -d

and my test node:RED program is this one:

node-RED1

It’s super easy to configure the mqtt subscribers and publishers, I used an injection node as a trigger and firstly saw that messages were flowing into mqtt and out to the debug module. Then I rewired it, clicked deploy, and then my tweet was sent straightaway! (the injector fires at startup by default).

 

 

Leave a Comment

Your email address will not be published.

83 − 80 =