Tuesday, 26 May 2015

Node-Red Raspberry Pi LED control via Pushbullet

I've been using Node-Red for a few days now and can't believe how powerful it is and although it has its moments it's not too difficult to use.
I've been searching the extra nodes and flows (a collection of nodes and functions added together to perform an action) that can be found here http://flows.nodered.org/ and found quite a few really useful contributions.

I decided to publish a simple flow that I created to switch on/off an LED connected to Pin11 of my RPi using my phone and Pushbullet.

Pushbullet is an app for Android, PCs (Chrome) and Iphones to broadcast information between your devices, for example I can get the notifications that appear on my Android phone to pop-up on my PC when I'm using the Google Chrome plugin.

What this flow does is when I send a push note from my phone containing the words "LED on" the push server sends it to my devices including the node on the RPi server the flow then sends a 1 to the output pin of the RPi switching the LED on and then sends a push note back to the phone with a confirmation "LED is on".  Sending "LED off" switches the LED off.

All this without having to know any Python at all..... brilliant!

The flow is available on GitHub Gist here or you can just copy the text below and paste it into the import from clipboard in node-red.
[{"id":"8cc62775.7339d8","type":"pushbullet-config","name":"Phil Grant"},{"id":"36bc98c5.c94368","type":"inject","name":"LED on","topic":"","payload":"LED on","payloadType":"string","repeat":"","crontab":"","once":false,"x":507,"y":450,"z":"6a77b09e.95885","wires":[["2b89fef6.d47602"]]},{"id":"2b89fef6.d47602","type":"switch","name":"LED Control","property":"payload","rules":[{"t":"eq","v":"LED on"},{"t":"eq","v":"LED off"}],"checkall":"true","outputs":2,"x":655,"y":504,"z":"6a77b09e.95885","wires":[["89d6dac1.762928","dba96b7a.245698"],["f6e1a3b9.091e6","cd9a199b.3265e8"]]},{"id":"dd181fd3.22e7e","type":"pushbullet in","config":"8cc62775.7339d8","name":"Push input","x":488,"y":505,"z":"6a77b09e.95885","wires":[["2b89fef6.d47602"]]},{"id":"89d6dac1.762928","type":"template","name":"On","field":"payload","format":"handlebars","template":"1","x":856,"y":487,"z":"6a77b09e.95885","wires":[["69f3331c.960ccc"]]},{"id":"dba96b7a.245698","type":"template","name":"LED is On","field":"payload","format":"handlebars","template":"LED is On","x":865,"y":453,"z":"6a77b09e.95885","wires":[["e69cd2aa.19633"]]},{"id":"f6e1a3b9.091e6","type":"template","name":"off","field":"payload","format":"handlebars","template":"0","x":855,"y":531,"z":"6a77b09e.95885","wires":[["69f3331c.960ccc"]]},{"id":"cd9a199b.3265e8","type":"template","name":"LED is Off","field":"payload","format":"handlebars","template":"LED is off","x":865,"y":564,"z":"6a77b09e.95885","wires":[["c099b247.3f665"]]},{"id":"1d5efe9b.e2a101","type":"inject","name":"LED Off","topic":"","payload":"LED off","payloadType":"string","repeat":"","crontab":"","once":false,"x":501,"y":568,"z":"6a77b09e.95885","wires":[["2b89fef6.d47602"]]},{"id":"69f3331c.960ccc","type":"rpi-gpio out","name":"Pin 11","pin":"11","set":true,"level":"0","out":"out","x":1024,"y":507,"z":"6a77b09e.95885","wires":[]},{"id":"e69cd2aa.19633","type":"pushbullet","config":"8cc62775.7339d8","pushtype":"note","title":"LED Status","chan":"","name":"LED is On","x":1032,"y":453,"z":"6a77b09e.95885","wires":[]},{"id":"c099b247.3f665","type":"pushbullet","config":"8cc62775.7339d8","pushtype":"note","title":"LED Status","chan":"","name":"LED is Off","x":1031,"y":564,"z":"6a77b09e.95885","wires":[]}]

Sunday, 24 May 2015

Shortcut Keyboard - Extended

Just a quick update to my shortcut keyboard.
I really started to use this while at work and found it really useful but there weren't enough buttons so I had an idea to double the size by getting some new acrylic fronts and backs made that were double the width and held two PCBs next to each other.

There are enough inputs left on the Arduino to connect the second set of buttons so no need for another Arduino.

I use Sketchup a lot and now I can attach several commands to the second set of buttons.

Tuesday, 12 May 2015

Discovering Node-red Part 1

Trawling around the various Arduino interest sites and blogs I quite often discover some new and very interesting information on some new topics and some not so new but un-known to me.

Sometime ago I'd read about a visual interface called Node-Red for designing IoT information flows and I was interested but didn't have the time to investigate so it was put on the back burner.

I then found out about the very versatile ESP-8266 that is a very inexpensive WiFi adapter for Arduino that comes in several flavours and can host a web page.

Anyway whilst I was searching around for info on the ESP8266 I found an excellent blog by Peter Scargill (here) and on his blog he'd written some posts about a couple of very interesting topics, node-red and Grovestreams.  In this post I'll try to give you a helping hand by describing my efforts to get it all up and running.

My goal was to have the RPi receiving temperature data from an external Jeenode via 868MHz (EU) using a Jeelink plugged into the RPi USB port, this would then be sent to Grovestreams to graph and also have twitter and/or email alerts setup dependent on temp. values.  Please remember though that I'm a beginner at this not an expert so there might be better ways to achieve this....

First - node-red
This software appears to be a visual interface that utilises Node.js which is a platform built on Chrome's JavaScript runtime.  There is an explanation on the node-red web page on installing both node.js and node-red for PCs and the Raspberry Pi.

Step one - installation
I decided to install node-red on My Windows7 PC first and if I could get it working I would brush the dust of my RPi and fire it up, I installed Node.js following the instructions here and then installed node-red, I think the installation is a little tricky unless you're confident using the command window in Windows but follow the instructions and you should be OK.

Step two - Run node-red
Node-red is run from a cmd window, I ran it using "run as administrator" from the right click context menu, when you run it it starts a server on your PC at http://localhost:1880 and this brings up the visual editor for creating your flows.
This is what my flow eventually looked like, I have added some descriptive text after the screen-grab was taken.

The layout shows all the different nodes down the left hand side, the editing window (where the nodes are dragged to) in the middle, the node information and debug output are on the right hand side (not shown).

Each node has a set of properties relevant to its purpose, i.e. if you double click the serial port node you will be able to configure the port details.

These grabs are from the RPi installation, the serial port names on PC install will look slightly different.
First dialog after double clicking
Click the pencil icon to get the config dialog.

Full serial port config dialog
The next node is called a switch node which can direct data to different outputs based on the incoming data, I realised later that I didn't need two nodes as one node can be given two outputs by adding a second rule.
The message from the transmitter contains labels for the temp. values, Greenhouse and Outside, this switch node uses these labels to direct the temp. values towards the matching Grovestream node.
Double clicking on the switch node opens the config dialog and each time you click on the +rule button, bottom left, you will add another decision and output branch.
The message payload is directed to the relevant output but it still contains the label and I want to remove the label so the next "function" node removes the label leaving just the temp. value.
I must admit that this function node took me a while to configure correctly, I can handle a few different programming languages but Javascript is not my favourite, the function basically splits the payload into parts around the ':' these 2 parts are referenced as 0 and 1 in an array and the second part [1] is passed on from the function thus removing the text label.

The input is Greenhouse Temp:20.1 and the output is 20.1

Once the value has been cleaned up it's ready to send off to my Grovesteams account, the Grove node has been written by Peter Scargill and the instructions to install it on Linux/RPi can be found here, for windows I downloaded the source files and placed them in a folder called "grove" in the following location: 

If installed correctly the purple node will appear in the list of nodes on the left hand side and is configured by double clicking.  Peter has a good "how to" guide on his blog here.

End of part one.

Three button WiFi Remote

Using the power control circuit from the Wirelesse door/Window sensor I have designed a simple 3 button WiFi remote with the intention of co...

Popular Posts