I recently discovered a really interesting new Open Source project for integrating devices and services, it’s called Node-RED. Sponsored by IBM, the project is built on node.js and describes itself as “A visual tool for wiring the Internet of Things”. It combines a graphical design tool that runs in a web browser and a runtime execution engine. Devices and services are represented by “nodes” which are wired together using the design tool to create a “flow”. Although a number of built-in nodes are provided there isn’t one for integrating an XBee wireless network so I rolled up my sleeves and built one.
My XBee “node” (there are definitely too many things called “node” in this project!) communicates with the XBee network through an XBee wireless module connected to the computer’s serial port. It uses the excellent svd-xbee node.js module to communicate with an XBee module configured as a network Coordinator, using the XBee API mode. I use the Sparkfun XBee Explorer USB to connect the XBee module to my serial port. If you need information on how to configure XBee modules take a look at my earlier posts on XBee.
To use the XBee node in your own Node-RED flow, follow these steps:
- Install node.js and Node-RED as per these instructions.
- Install svd-xbee module. Currently the XBee node depends on the latest version of svd-xbee which is only available directly from GitHub.
$ npm install git+https://github.com/jouz/svd-xbee.git
- Download or clone the XBee node from GitHub https://github.com/freakent/NR-XBee.git
$ git clone https://github.com/freakent/NR-XBee.git
- Edit and run the XBee node’s install script
Edit the install.sh script and change the NR_HOME variable to match the directory where you installed Node-RED. Make sure the script is executable and then run it.
$ chmod +x install.sh
- Connect your Coordinator configured XBee module into a USB port and take note of the serial port your operating system associates it with.
On MacOS you can use
$ ls /dev/tty.usb*
- Start up your Node-RED installation, as per the instructions here.
Hopefully Node-RED will start up and you shouldn’t see any error messages relating to either the Serial or XBee nodes.
- Check the XBee components are available in the Node-RED console
Fire up your web browser and point it at the URL given to you during Node-RED startup, typically http://127.0.0.1:1880/. The XBee node should be visible in the palette on the left as input and output nodes. You can now drag an XBee node into your flow and configure it as required.
Eventually Node-RED will support nodes being installed as regular npm modules so hopefully these instructions should get shorter in the future.
I now have everything I need to create v3 of my iDoorbell project, replacing Apache ServiceMix with Node-RED. Node-RED is looking like a much simpler and easier to use integration solution for me. Watch this space to see how it turns out.