Expected completion time of this lab:
. |
Node-RED is fun little tool from IBM Research to "wire up the IoT". You will use the JsonServer
application to interface Node-RED to your SmartMesh IP network.
Node-RED is fun tool from IBM Research to "wire up the IoT". It's a little program you launch of your computer, which allows you link inputs (sensors, etc.) to outputs (actuators, files, Twitter feeds, etc) through a web-based graphical interface.
What is Node-RED? |
The first step is to install Node-RED.
npm
is the "node package manager", part of Node.js)C:\Users\twatteyne>npm --version 2.15.9 |
npm:
npm install -g --unsafe-perm node-red |
C:\Users\twatteyne>node-red Welcome to Node-RED =================== 1 Sep 15:02:04 - [info] Node-RED version: v0.14.6 1 Sep 15:02:04 - [info] Node.js version: v4.5.0 1 Sep 15:02:04 - [info] Windows_NT 6.1.7601 x64 LE 1 Sep 15:02:04 - [info] Loading palette nodes 1 Sep 15:02:05 - [warn] ------------------------------------------------------ 1 Sep 15:02:05 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node 1 Sep 15:02:05 - [warn] [tail] Not currently supported on Windows. 1 Sep 15:02:05 - [warn] ------------------------------------------------------ 1 Sep 15:02:05 - [info] Settings file : C:\Users\twatteyne\AppData\Roaming\npm\ node_modules\node-red\settings.js 1 Sep 15:02:05 - [info] User directory : \Users\twatteyne\.node-red 1 Sep 15:02:05 - [info] Flows file : \Users\twatteyne\.node-red\flows_HDC_SW 01.json 1 Sep 15:02:05 - [info] Creating new flow file 1 Sep 15:02:05 - [info] Starting flows 1 Sep 15:02:05 - [info] Started flows 1 Sep 15:02:05 - [info] Server now running at http://127.0.0.1:1880/ |
JsonServer
applicationThe |
This application is part of the SmartMesh SDK. To start it, double-click on JsonServer.py
.
We assume that you have a SmartMesh IP manager connected to the computer which runs the JsonServer
application, and a couple of motes already in the network.
In this section, we will create a number of Node-RED flows to interact with your SmartMesh IP network directly from Node-RED!
JsonServer
Create a flow in Node-RED to issue the following HTTP request:
method | GET |
---|---|
URI | http://127.0.0.1:8080/api/v1/status |
body | none |
What is the response from the manager?
Use Node-RED to issue the following HTTP request:
method | GET |
---|---|
URI | http://127.0.0.1:8080/api/v1/helpers/serialports |
body | none |
What is the response from the manager?
Use Node-RED to issue the following HTTP request:
method | PUT |
---|---|
URI | http://127.0.0.1:8080/api/v1/config/managers |
body | { |
Replace the serial port number above by yours. |
After you issue this command, retrieve the status of the manager. What is the status of your manager?
Use Node-RED to issue the following HTTP request:
method | GET |
---|---|
URI | http://127.0.0.1:8080/api/v1/helpers/motes |
body | none |
What is the response from the manager?
Use Node-RED to issue the following HTTP request:
method | PUT |
---|---|
URI | http://127.0.0.1:8080/api/v1/oap/00-17-0d-00-00-38-06-45/digital_out/INDICATOR_0 |
body | { "value":1} |
What is the configuration of the "LED on" widget?
What is the configuration of the "LED off" widget?
What is the configuration of the "http request" widget?
Use Node-RED to receive the following HTTP requests
method | POST |
---|---|
URI | /oap |
Add a function so the debug console prints only the temperature values received, in C.
What is the configuration of the "function" widget?
Install the following control loop: set the LED of one mote iif the temperature measured by the other mote is larger than 20C, clear otherwise:
MQTT and HiveMQ. |
MQTT allows you to coordinate two independents flows, possibly running on different computers.
For that, create two flows:
A first flow which publishes temperature to the HiveMQ MQTT broker on topic DustAcademy/temperature
:
A second flow subscribed to this broker and topic, and switches the LED on/off depending on the temperature value:
You can run both flows on different computers, each connected to a different SmartMesh IP network. |