Use Node-RED to create a gateway between MySensors and Blynk (local server)

Blynk is great for using and control connected objects from your iOS or Android smartphone. If you have developed objects connected using the MySensors library to communicate over long distances using radio waves, it is very easy to return the data using Node-RED. This tutorial only deals with sending data from a MySensors probe. We will see in a next tutorial how to control MySensors actuators from the Blynk application.

Before you begin

If you do not already have Node-RED, follow the tutorial that corresponds to your environment:

You can also read this tutorial to learn how to easily manage modules.

Install node-red-contrib-blynk-websockets for Node-RED

Open the palette manager and do a search on the keyword Blynk. You should get 2 modules:

  • Node-red-contrib-blynk
  • Node-red-contrib-blynk-websockets. The npm page of the plugin is here

node-red plugin blynk

The first plugin (node-red-contrib-blynk) is now obsolete. It still works but will not receive any updates. Install the 2nd plugin node-red-contrib-blynk-websockets. Once the installation is complete, you will have a new palette composed of 4 tools

  • read event: retrieve read events
  • write event: retrieve write events
  • write: allows to publish something on Blynk
  • email: allows to use an email via the Blynk server

At the time of writing this article, the plugin is not yet documented. I had to look a bit. I’ll have to apologize if there are any errors. In any case do not hesitate to share if you have any other information than mine.

node-red-contrib-blynk-websockets palette

Using Node-RED as a gateway between MySensors and Blynk

Node-RED lends itself very well to this game. Apart from decoding the messages (the flow is lower) coming from the Gateway MySensors, there will be no programming. Here’s how we’ll do it:

  • The sensor transmits the measurements by radio waves (2.4GHz) to the Gateway MySensors (follow this tutorial to make a WiFi network gateway).
  • One connects to the MySensors network gateway from Node-RED using flow TCP/IP.
  • MySensors are decoded
  • Each measure is sent to the Virtual Ply of the Blynk project
  • The Blynk server receives the data
  • The mobile application connects to the Blynk server to retrieve the measurements

Node-RED MySensors to blynk gateway.

Connecting to the MySensors Gateway

To connect to a network gateway, we will use the TCP Node

node-red tcp mysensors lan gateway

Configure the connection as follows:

  • Type: Connect to
  • Port: 5003 by default (to suit your configuration)
  • At host: the ip address of the network gateway
  • Output: stream of … String
  • Give a name
  • Save with Done

node-red tcp mysensors lan gateway settings parametres

Decode MySensors messages

In this tutorial we saw how to decode on-the-fly messages received by the MySensors gateway. We will use it again because we have to send the data individually to Blynk. Paste the decoder flow into your Node-RED project and connect it to the previously created TCP Node.

Installation of the gateway

Now that the messages are decoded, we will be able to extract what we are interested in and send it to Blynk. To do this, you need to retrieve the following information:

  • The Token of the project on which you want to publish the data
  • The virtual pins on which to send the data. Here it will be V0 for temperature and V1 for humidity
  • The IP address of the Blynk server and the websocket port

Node-RED will communicate in Websocket with the Blynk server. For a non-secure link, the default port is 8082.

If you have your own local Blynk server, replace IP_BLYNK_SERVER with the IP address. If you used your official Blynk account, the server is cloud.blynk.cc.

Finally if you have set up an SSL certificate, you can secure the exchanges with Node-RED by logging onto the websocket

You can change the ports in the Blynk server.properties configuration file

In the Node-RED palette, search the keyword Blynk. Place the write Node on the flow

node-red blynk contrib websocket write

Press the pencil to the right of the pick list to add a connection

  • Url: the url of the websocket
  • Project key: the token to which the data is to be sent
  • Name: give a name to the connection
  • Save the configuration

node-red blynk contrib websockets url

Back in the Node write:

  • Select the connection from the list.
  • Indicate the virtual Pin (just the number).
  • Give a name
  • Save

 node red blynk websocket mysensors write virtual pin

Do the same for moisture. Connect the Node Write to the measurement extraction filter. Here’s what you need to get

node-red mysensor blynk gateway passerelle

The complete flow code

Deploy flow and open the Blynk application on your iOS or Android smartphone. You now receive data from your MySensors objects without any changes to their code.

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

Tags:

DIY Projects