|
This recipe is outdated and replaced by SmartMesh IP and Node-RED, revisited. |
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.
SmartMesh IP and Node-RED are a perfect match. I'll show you a couple example in this tutorial. You will be using off-the-shelf applications from the SmartMesh SDK; you won't even have to write a line of code!
To replicate this tutorial, you need to have:
We assume the motes are running the default firmware, in Master mode. We assume the manager is connected your computer over USB, and that all the motes are switched on and 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.
npm
is the "node package manager", part of Node.js)C:\Users\twatteyne>npm --version 2.15.9 |
npm:
sudo 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/ |
Following the excellent Getting Started guide if you want to learn more about Node-RED. |
Our first Node-RED "flow" (the connections between inputs and outputs, in Node-RED parlance) is to receive temperature data generated by SmartMesh IP motes directly in Node-RED. We will use for that the PublishToWeb sample application of the SmartMesh SDK.
PublishToWeb
SmartMesh SDK sample applicationThe PublishToWeb sample application is part of the SmartMeshSDK. |
Before launching the PublisToWeb application, edit PublishToWeb.py
and replace the SERVER_HOST
and SERVER_PORT
variables by:
SERVER_HOST = 'localhost' SERVER_PORT = '1880' |
This makes sure the application will publish to the Node-RED instance running locally on your computer.
You can now launch the PublishToWeb application, and connect it to the serial API port of your SmartMesh IP Manager, COM31
in my case:
PublishToWeb - (c) Dust Networks SmartMesh SDK 1.0.8.142 SmartMesh IP manager's API serial port (leave blank for COM7): COM31 Connected to COM31. sent mac=00-17-0d-00-00-38-05-da temperature=21.79C sent mac=00-17-0d-00-00-38-03-ca temperature=23.29C sent mac=00-17-0d-00-00-38-04-35 temperature=22.65C sent mac=00-17-0d-00-00-38-05-da temperature=21.79C sent mac=00-17-0d-00-00-38-03-ca temperature=23.50C sent mac=00-17-0d-00-00-38-04-35 temperature=22.86C sent mac=00-17-0d-00-00-38-03-ca temperature=23.72C sent mac=00-17-0d-00-00-38-05-da temperature=22.00C |
You will see a line print each time the application receives a temperature reading from one of the motes.
Drag and drop the following "nodes" to build the following flow:
Create the following links:
Click the "Deploy" button to activate this flow. In the debug tab on the right, you see the temperature appear each time one of the mote publishes.
Congratulations! You now have successfully published data into Node-RED. Now that the data is there, sky is the limit: you can publish that data live on Twitter, log it into a file, publish it over MQTT, publish it to a webpage through a websocket, etc.
The following code is the textual representation of the Node-RED flow above. You can simply paste this in the "Import > Clipboard" utility in Node-RED:
|
The goal of this Node-RED flow is to toggle the mote's LED by click on the Node-RED interface:
JsonServer
SmartMesh SDK sample applicationThe JsonServer sample application is part of the SmartMeshSDK. |
JsonServer - SmartMesh SDK 1.0.8.142 (c) Dust Networks serial port of SmartMesh IP Manager (e.g. COM15): COM31 ok. connected to manager at COM31 ok. JSON server started on port 8080 |
Drag and drop the following "nodes" to build the following flow:
a "function" node, double-click on it and set the code to:
msg.headers = { "Content-type" : "application/json" } msg.payload = { "mac": "00-17-0D-00-00-38-07-01", "state": msg.payload } return msg; |
Create the following links:
Click the "Deploy" button to activate this flow. You can now on the "led on" and "led off" nodes to change the state of the blue LED of your DC9003 mote.
On your DC9003 mote, make sure the "LED EN" jumper is closed. |
The following code is the textual representation of the Node-RED flow above. You can simply paste this in the "Import > Clipboard" utility in Node-RED:
|
This tutorial has shown you how to send data from your SmartMesh IP network into Node-RED, and from Node-RED into your SmartMesh IP network.
These are the only building blocks you need to integrate SmartMesh IP and Node-RED.
You now have an infinity of possibilities for building applications which publish to different back-end solutions, create complex triggers in a home-automation system, connect sensors to actuators, etc.