SmartMesh IP and Node-RED, revisited

SmartMesh IP and Node-RED, revisited

This recipe updates the previously published "SmartMesh IP and Node-RED" recipe. In this recipe, we use the JsonServer SmartMesh SDK application; it's now even simpler to interface with Node-RED!

 

Overview of Node-RED

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!

Requirements

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.

Setup

Installing Node-RED

The first step is to install Node-RED.

Running the JsonServer application

This application is part of the SmartMesh SDK. To start it, double-click on JsonServer.py.

Starting your network

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.

Interact with your SmartMesh IP nodes using Node-RED!

In this section, we will create a number of Node-RED flows to interact with your SmartMesh IP network directly from Node-RED!

Retrieve the status of the JsonServer

Use Node-RED to issue the following HTTP request:

To do so, in Node-RED, create a flow called "status" with the following contents:

JSON version of the flow

[{"id":"3eb439e9.a16146","type":"inject","z":"8c6d627b.da73c","name":"click to get status","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":146.5908966064453,"y":65.63638305664062,"wires":[["97cbb847.431838"]]},{"id":"97cbb847.431838","type":"http request","z":"8c6d627b.da73c","name":"","method":"GET","ret":"txt","url":"http://127.0.0.1:8080/api/v1/status","tls":"","x":271.59088134765625,"y":161.8182144165039,"wires":[["a459d098.1a269"]]},{"id":"a459d098.1a269","type":"debug","z":"8c6d627b.da73c","name":"","active":true,"console":"false","complete":"false","x":366.5908660888672,"y":261.72728729248047,"wires":[]}]

List the available serial ports

Use Node-RED to issue the following HTTP request:

To do so, in Node-RED, create a flow called "serialports" with the following contents:

JSON version of the flow

[{"id":"83b5eea0.77e04","type":"inject","z":"1815fc03.041354","name":"click to get serialports","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":249,"y":123,"wires":[["802c15cd.802598"]]},{"id":"802c15cd.802598","type":"http request","z":"1815fc03.041354","name":"","method":"GET","ret":"txt","url":"http://127.0.0.1:8080/api/v1/helpers/serialports","tls":"","x":353.99998474121094,"y":219.18183135986328,"wires":[["e13a0a2c.06ff08"]]},{"id":"e13a0a2c.06ff08","type":"debug","z":"1815fc03.041354","name":"","active":true,"console":"false","complete":"false","x":448.9999694824219,"y":319.09090423583984,"wires":[]}]

Connect to your SmartMesh IP Manager

Use Node-RED to issue the following HTTP request:

method

PUT

URI

http://127.0.0.1:8080/api/v1/config/managers

body

{ "managers": ["COM10"] }

To do so, in Node-RED, create a flow called "managers" with the following contents: