Tag Archives: Blynk as a web controller using Node-Red

Blynking Wonderful

As of yesterday, a new release of the Blynk App has been released which makes me want to look at this  again.

Regular readers know that I’m into the idea of using a central controller for home control – so that instead of trying to give every peripheral every feature on the planet, I’ve chosen to use Node-Red on a Raspberry Pi or similar. This has the ability to send emails, send and receive data to and from peripherals and to handle a variety of functions – many as simple as dragging a box onto the screen – yet allows complex programming in the same environment if required.

There are as many ways to fit a UI to Node-Red as there are ways to talk to peripherals – node-red-contrib-ui is one of the leading candidates but you can easily talk to NR via HTTP, web sockets and other drop-in technologies. At one time, NETIO was a great candidate but I’ve not seen that improving for a long time – a shame as there’s a nice visual web editor. Node-Red-Contrib-UI is a very hot contender as it is easy to use but I suspect the sole developer is busy elsewhere right now.

BlynkMeanwhile there is Blynk – available for Android and IOS. The basic principle is that this app talks to a “blynk server” – either theirs or a local copy (a pair of JAR files), which keeps track of changes to devices. The likes of Arduino, ESP and others can talk to the Blynk server via special (and freely available) oftware.   Some time ago a set of nodes was released for Node-Red which would talk to the server and hence the Blynk app – but the nodes were not reliable – I spent ages talking to the author and was about to give up when he adopted a new approach – and suddenly the nodes became super-reliable – no doubt a combination of his work and improvements to the Blynk server.

The designers of Blynk had (I think) always imagined that only their APP would be controlling devices – it didn’t seem to occur to them that there might be people like me using Node-Red to perform all sorts of automation tasks on devices and merely using Blynk as a remote control mechanism. Until now, if changes were made to, say, the state of a relay while the Blynk app was on pause (perhaps the phone was handling emails, the App would not know about this until the user logged out and back in.

And so for some time I gave this a miss. That has all changed now and so it is time to look again.

So – the Blynk server – make sure you have at least Java 8 on whatever device you are running Node-Red on – in my case a Raspberry Pi 2 - http://docs.blynk.cc/#blynk-server

I created the directory  /home/pi/Blynk  and dropped in the server.jar and admin.jar files – and created a text file called server.properties.

The latter file contains nothing more than this.

#web sockets ssl port
ssl.websocket.port=8081
#web sockets plain tcp port
tcp.websocket.port=8082

I chose to give full permissions to the folder Blynk – if someone understands permissions better and would like to suggest a sensible minimum for that  - happy to get feedback You can also put gmail details in here if you want so the server can email you but we’ll leave that for now.

To activate this at powerup I went into a Pi terminal and typed..

crontab –e

As this was the first use of that command on the particular machine – it asked me which editor I’d like to use – sadly you don’t get the choice of Notepad++ on the Pi so I settled for Nano.

At the end of the file I added..

@reboot java -jar /home/pi/Blynk/server.jar -dataFolder /home/pi/Blynk &

and saved the file – and rebooted the Pi. Server now running locally. You can test that with the APP by (in the app) registering with the server.

Finally you need the Node Red nodes from here.

npm install node-red-contrib-blynk-websockets

The connection in the Node-Red-Node will look something like this.. depending on your port setup – and yes you could make it available externally via a port redirect..

ws://127.0.0.1:8082/websocket

and a long ID number you get off the app.

And that, in a nutshell just works – well it works for me. I now have this running on 2 Raspberry PIs and will tomorrow add it to my Orange Pi installation.

Apparently the App will not always be free so I’d be getting yours now while it is! I just hope when they go commercial, they remember all the people who have contributed to getting it this far – oh and GIVE US A SMALLER RGB controller!!

Let’s hope node-red-contrib-UI continues to develop to keep the competition healthy!

Facebooktwittergoogle_pluspinterestlinkedin