Tuesday, June 10, 2014

Connecting things to Internet

IoT is nothing without the physical things connected. Here is a simple example how to use Node-RED to connect things to Internet.

Node-RED makes it easy to connect the physical world into the IoT. Wireless Sensors are one example of things, and applied in this exercise.

Raspberry Pi with JeeLink attached, and JeeNode USB at back.
JeeNode is a family of inexpensive AVR MCU boards with integrated RFM12 radio module. RFM12 is an inexpensive Sub-1GHz RF transceiver for unlicensed ISM bands (315,433,868,915MHz). JeeNodes are compatible with Arduino development environment and there is RFM12 library available, which makes it very easy to start experimentation.

System diagram
Raspberry Pi acts as a gateway receiving messages send by wireless nodes, processing the data and forwarding it to MQTT broker, Twitter, etc. All software development in RPi has been done in Node-RED.

Wireless sensor transmits following JSON messages:
{
  "topic": "egg",
  "payload": "jeenode"
}
The format is compatible with the internal representation of flow data elements in Node-RED. These messages are received by the serial port receiver node.

Serialport handler in Node-RED
Handling serial port in Node-RED is very easy. After installing serialport package (npminstall serialport) and restarting the Node-RED service, there appears one new node in the Node-RED editor: serial. Here the serial port receiver has name "RFM12".

Node-RED serial port configuration window.
Messages received from serial port appear in msg.payload. If the message is JSON formatted, as is the case in this example, it is very easy to parse it to create a new msg with corresponding attributes. This function node called here as "JSON" is the only place in this example where Javascript/Node.js code is written manually.

Custom function to parse JSON messages received from serial port.
There may appear messages with different topics, thus a switch node is used to select proper processing flow for each topic. In this example, only messages with topic 'egg' are taken into further processing.

Configuration window for switch rules in Node-RED.
Simple as that! Now where are ready to do whatever whit the data received, to send it to MQTT broker or Twitter for example.

No comments:

Post a Comment