|
This recipe updates the previously published "SmartMesh IP and Node-RED" recipe. In this recipe, we use the |
Node-RED is a fun tool from IBM Research to "wire up the IoT". It's a program you launch on your computer, which allowing you to link inputs (sensors, etc.) to outputs (actuators, files, Twitter feeds, etc.) through a web-based graphical interface.
SmartMesh IP and Node-RED are a perfect match. I'll show you a couple of examples in this recipe. You will be using the brand new JsonServer
application from the SmartMesh SDK; you won't even have to write a line of code!
To complete this tutorial, you need to have:
We assume the motes are running the default firmware, in master mode. We assume that the manager is connected to your computer over USB, that all the motes are switched on, and that all motes have joined the network. We assume you have downloaded the SmartMesh SDK, and are comfortable enough with it that you can launch different applications. |
The first step is to install Node-RED.
JsonServer
applicationThis 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
Use Node-RED to issue the following HTTP request:
method | GET |
---|---|
URI | http://127.0.0.1:8080/api/v1/status |
body | none |
To do so, in Node-RED, create a flow called "status" with the following contents:
|
Use Node-RED to issue the following HTTP request:
method | GET |
---|---|
URI | http://127.0.0.1:8080/api/v1/helpers/serialports |
body | none |
To do so, in Node-RED, create a flow called "serialports" with the following contents:
|
Use Node-RED to issue the following HTTP request:
method | PUT | |
---|---|---|
URI | http://127.0.0.1:8080/api/v1/config/managers | |
body |
|
To do so, in Node-RED, create a flow called "managers" with the following contents:
|
Use Node-RED to issue the following HTTP request:
method | GET |
---|---|
URI | http://127.0.0.1:8080/api/v1/helpers/motes |
body | none |
To do so, in Node-RED, create a flow called "motes" with the following contents:
|
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 |
|
To do so, in Node-RED, create a flow called "LED" with the following contents:
|
Use Node-RED to receive the following HTTP requests:
method | POST |
---|---|
URI | /oap |
The JsonServer application continuously receives notifications from the SmartMesh IP manager over its serial port. This includes data notifications. Its default behavior is to issue an HTTP POST request to url Port 1880 is precisely the port Node-RED runs on by default. This means that, by simply listening for HTTP requests on URI |
Add a function so the debug console prints only the temperature values received, in C.
|
You can install the following very simple control loop: set the LED of one mote if the temperature measured by the other mote is larger than 20C
|
MQTT allows you to coordinate two independent flows, possibly running on different computers.
For that, create two flows:
The first flow publishes the temperature to the HiveMQ MQTT broker on topic DustAcademy/temperature
:
|
The second flow subscribes to this broker and topic, and switches the LED on/off depending on the temperature value:
|