Developing IoT Mashups with Docker, MQTT, Node-RED, InfluxDB, Grafana

Page for the tutorial " Developping IoT Mashups with Docker, MQTT, Node-RED, InfluxDB, Grafana " at Eclipse IoT Days Grenoble 2016

COMING SOON

=Install Docker=

=Install Node.js and NPM= On Raspian sudo apt-get install nodejs npm

=Install Node-RED=

On Raspian Jessie sudo apt-get update sudo apt-get install nodered

Browse http://127.0.0.1:1880/

Now, you can write your own Node-RED flows and functions.

Install the admin cmdline tool

npm install -g node-red-admin node-red-admin help

node-red-admin list
 * 1) installed modules

node-red-admin search serial node-red-admin search rfxcom node-red-admin search zwave node-red-admin search ble node-red-admin search bluetooth node-red-admin search sensortag
 * 1) search modules

node-red-admin search beaglebone node-red-admin search gpio

node-red-admin search mongodb node-red-admin search redis node-red-admin search cassandra node-red-admin search elastic node-red-admin search influxdb node-red-admin search kafka

Remark: node-red-admin install does not work ! Use

cd ~/.node-red npm install -g node-red-node-redis npm install -g node-red-contrib-kafka-consumer npm install -g node-red-node-mongodb

Restart Node-Red

node-red-admin list

=Install extra nodes for Node-RED= Extra nodes are provided with the Node-RED community. There are listed here.

Serial for Geiger Counter
Connect the Geiger counter to the host.

Check available serial ports (/dev/tty.usbserial* on MacOS X, ...) with.

Add a node serial "Geiger" with a Settings of 9600/8/N/1 and 'Split input into fixed lenghts of 1 chars'.

Add a node debug.

Connect "Geiger" to debug.

Deploy the flow.

The Geiger Counter sends a random sequence of 0 and 1.

Add a node function "Count Particles" with a flow-scoped variable (geiger/count): var COUNT='geiger/count';

// initialise the counter to 0 if it doesn't exist already var count = flow.get(COUNT)||0; count += 1; // store the value back flow.set(COUNT,count); // make it part of the outgoing msg object msg.count = count; msg.payload = count;

node.log("Received particles : " + count);

return msg;

Connect node "Geiger" to node "Count Particles".

Deploy the new flow.

Edit the node "Count Particles" and add the 2 following statements in order to display the count into the node's status. ... setTimeout(function { node.status({}); }, 1000) node.status({fill:"green",shape:"dot",text:"#"+count}); return msg;

Deploy the new flow.

Add a node inject "One minute timer" with a repeat interval of 1 minute.

Add a node function "Reset Particles Count" with a flow-scoped variable (geiger/count): var COUNT='geiger/count';

// initialise the counter to 0 if it doesn't exist already var count = flow.get(COUNT)||0;

msg.count = count; msg.payload = count;

node.log("Reset counter at " + count);

// make it part of the outgoing msg object count = 0; // store the value back flow.set(COUNT,count);

return msg;

Connect node "One minute timer" to node "Reset Particles Count" and node "Reset Particles Count" to node debug.

Deploy the new flow.

The result is:

Install RFXCom for Oregon Sensors


Install the rfxcom node (node-red-contrib-rfxcom) cd ~/.node-red npm install -g node-red-contrib-rfxcom

Restart Node-RED with.

Connect the RFXCom receiver to the host.

Check available serial ports (/dev/tty.usbserial* on MacOS X, ...) with.

Add a node rfxcom-sensors "RFXCom" with the correct serial port.

Add a node debug display the full message (not only msg.payload).

Connect "RFXCom" to debug.

Deploy the flow.

The flow loos like that:

Serial for Arduino
Install the serial node (node-red-node-serialport) npm install node-red-node-serialport or sudo npm install -g npm@2.x npm install node-red-node-serialport@0.0.5 if node.js prior to 4.x (ie v0.10.x and v0.12.x)

Restart Node-RED with.

Check the module in the list node-red-admin list | grep serial

Check available serial ports (/dev/tty.usbserial* on MacOS X, /dev/ttyUSB* ...) with.

TO BE CONTINUED

Serial for LoRa Libelium
Install the serial node (node-red-node-serialport) npm install node-red-node-serialport or sudo npm install -g npm@2.x npm install node-red-node-serialport@0.0.5 if node.js prior to 4.x (ie v0.10.x and v0.12.x)

Restart Node-RED with.

Check the module in the list node-red-admin list | grep serial

Check available serial ports (/dev/tty.usbserial* on MacOS X, /dev/ttyUSB* ...) with.

Serial for LoRa Nucleo
Install the serial node (node-red-node-serialport) npm install node-red-node-serialport or sudo npm install -g npm@2.x npm install node-red-node-serialport@0.0.5 if node.js prior to 4.x (ie v0.10.x and v0.12.x)

Restart Node-RED with.

Check the module in the list node-red-admin list | grep serial

Check available serial ports (/dev/tty.usbserial* on MacOS X, /dev/ttyUSB* ...) with.

TO BE CONTINUED

UDP for LoRaWAN
Add a node 'udp in' listening the port 8123.

Add a node 'function' "toString" with the following statement: msg.payload=msg.payload.toString; return msg;

Add a node 'debug'.

Connect them together.

Deploy the new flow.

Test the flow with the shell command echo -n -e "{'device'='123456','temperature'=37.2}" > /dev/udp/127.0.0.1/8123

The flow looks like that:

Add a node 'json' into the flow.

Now you can filter and send the output of a process to the flow througth an 'udp in' node.

TO BE CONTINUED

UDP for ESP8266
Add a node 'udp in' listening the port 8123.

Add a node 'function' "toString" with the following statement: msg.payload=msg.payload.toString; return msg;

Add a node 'debug'.

Connect them together.

Deploy the new flow.

Test the flow with the shell command echo -n -e "{'device'='123456','temperature'=37.2}" > /dev/udp/127.0.0.1/8123

Add a node 'json' into the flow.

ACR122U NFC Reader
Plug the ACR122U NFC reader in the host and check it with

Install LibNFC (on Debian) sudo apt-get install libnfc-dev libnfc-bin libnfc-examples

sudo nfc-list

Launch nfc-poll and put a NFC card/tag on the reader sudo nfc-poll -v

The ID of the NFC card/tag is prefixed by the string.

=Install Mosquitto=

=Install InfluxDB=

=Populate InfluxDB from Node-RED=

influx

Enter the following InfluxDB statements create database iotdb use iotdb show measurements show series select * from temperature select * from humidity

In the Node-RED dashboard, create a new flow to collect sensors data from the MQTT server.

Install the Node-RED InfluxDB node.

Restart Node-RED.

Add a node mqtt in "MQTT Broker" for subscribing to the MQTT server (broker is test.mosquitto.org or localhost topic is iotdays/sensors/#)

Add a node function "Tranform into time series" to format the JSON messages into time series messages.

Add a node influxdb out "IoT Database" with the InfluxDB server.

Connect the node "MQTT Broker" to node "Tranform into time series" and to the node "Tranform into time series" to node "IoT Database".

The flow looks like than:

=Install Grafana=

=Visualize sensors data into the Grafana dashboard=

=Install Apache Spark=

=Process a stream of sensors data=