Node-RED and XBee

Node-RED XBeeI 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:

  1. Install node.js and Node-RED as per these instructions.
  2. 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
  3. Download or clone the XBee node from GitHub https://github.com/freakent/NR-XBee.git
    $ git clone https://github.com/freakent/NR-XBee.git
  4. 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
    $ ./install.sh
  5. 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*
  6. 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.
  7. 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.

Chris Jefferies

28 April 2014

I originally got the serial nodes to read all the raw data coming in on my xbee series 1 radios, /dev/ttyO2:9600. Now I've got this NR-XBee loaded but sadly I don't understand how it's to be configured. The xbee nodes are available and I loaded the example flow. My goal is to have a dozen remote xbee radios transmitting 4 ADCs each and occasionally, based on some condition, like LDR detects dark, send a signal back, like setting D4 to x04,to close relay to turn on lamp. Using a Beaglebone Black, UART2, /dev/ttyO2, xbee series 1 coordinator in api2 mode. Any tips appreciated. Thanks, Chris.

martin

28 April 2014

Chris, it should be straight forward to configure. I have Series 2 XBees so your setup may have to be different. The XBee node only has two configuration options, a name and the serial port. You can name it anything you like and the serial port is configured in exactly the same way as the serial port node (it actually uses the same code underneath). Easiest thing to do is to create a flow with just the XBee node and a debug node, connecting the Xbee output to the debug node.

Robb GG

24 October 2014

I've been trying to use your plugin for a server to communicate with multiple xbee endpoints and I was wordering if you colud provide some help with getting it working. I have the node-red flow set up to return a timestamp when it's sent a message with "Time Please" as the payload and it should be sending a packet out with a UNIX timestamp in to the endpoint but it doesn't seem to be reaching it's destination and I'm not sure where to go from here. I've attached a serial sniffer and data is definately being sent to the xbee from node-red but it doesn't seem to be reaching the endpoint. If you could offer any tips that would be much appreciated. Thanks, // Robb

martin

03 November 2014

Sorry flor slow reply, your comment was hidden amongst a sea of comment span. It sounds more like a connectivity issue than a node-red issue. I'd connect the end point to X-CTU or better still both the end-point and the coordinator. Have you checked your PAN ID, DH and DL settings on each XBEE? What is your end point connected to?

Robb GG

05 November 2014

Thanks for the reply, I've checked all the config of the Xbees and it all looks ok, when I hooked a serial sniffer up to the DIN pin on the coordinator Xbee it seemed that the packets were malformed. I can re-build the setup and get some sample data if you'd like. // Robb

Robb GG

05 November 2014

Sorry about the double post, the endpoint is mean to be connected to an arduino but I've got it hooked up to a computer to use for debugging at the moment.

Waldo C

05 February 2015

Hi, I've already installed the module, and it's up and running in node-red. However, I can't change the serial port on the node. The "edit" button just doesn't bring up a new dialog. Have you come across this issue before? If so, do you know the workaround? Thanks!

martin

09 February 2015

I wonder if it is a problem with the version of Node-Red. I guess I'm still using a relatively old version. Now that 10.1 is out I should think about updating all my nodes to works as npms.

Chris

30 March 2015

Hi, I tested your method and it works! Thanks for this excellent post. I now can send messages from my Arduino to node-red using the XBee Series 2 in API Mode 2. But it left a few questions to me. I'm not a Javascript guy and tried quite some time to display the HEX values of the payload using the DEBUG node. It works (using a function node with toChar and toString(16), but only for values in the ASCII range. I tried the Binary Buffer feature of the serial connection as well, but with no luck. I guess, I don't understand the basic concepts of node-red. Is it suitable for binary data, and where is the direction to look or go? The second question is about sending a status response, but this is for later. Many thanks for any ideas or help! Chris

Waldo C

28 April 2015

Hello again, I managed to get it working on node-red's latest release (0.10.6). I'm using two API routers set to ATAP=2 (as per svd-xbee config instructions). However, I'm getting an error that makes node-red to crash. I don't know if it something to do my installation (i.e., a dependency problem or something missing) or the configuration of my xbee devices. Any help would be much appreciated! Thanks! This is the log: 28 Apr 14:01:28 - About to initialise the XBee on /dev/ttyUSB0:9600... 28 Apr 14:01:28 - [info] Started flows 28 Apr 14:01:29 - XBee initialised in pool -> {"panid":"0000000000008888","id":" ","sourceHigh":"0013a200","sourceLow":"40a7XXXX","nodeDiscoveryTime":6000} 28 Apr 14:01:29 - [info] [xbee in:myXbeeCoordinator] XBee node 0013a20040a7XXXX discovered 28 Apr 14:01:29 - [info] [xbee in:myXbeeCoordinator] XBee node 0013a20040adXXXX discovered 28 Apr 14:01:29 - [red] Uncaught Exception: 28 Apr 14:01:29 - TypeError: Cannot read property 'hex' of undefined at Node. (/home/waldo/Desktop/node-red-0.10.6/nodes/freakent-nodes/55-xbee.js:69:63) at Node.emit (events.js:98:17) at Node._onDataSampleRx (/home/waldo/Desktop/node-red-0.10.6/node_modules/svd-xbee/index.js:512:8) at SerialPort.self._onDataSampleRx (/home/waldo/Desktop/node-red-0.10.6/node_modules/svd-xbee/index.js:198:35) at SerialPort.emit (events.js:95:17) at Object.parser (/home/waldo/Desktop/node-red-0.10.6/node_modules/svd-xbee/lib/xbee-api.js:361:21) at ReadStream.SerialPort.options.dataCallback (/home/waldo/Desktop/node-red-0.10.6/node_modules/svd-xbee/node_modules/serialport/serialport.js:92:13) at ReadStream.emit (events.js:95:17) at ReadStream. (_stream_readable.js:765:14) at ReadStream.emit (events.js:92:17)

martin

28 April 2015

Looks like you found a typo, and (I'm ashamed to say) an untested bit of code. I think line 69 should read: node.log(util.format("IO from %s -> %s", xnode.remote64.hex, util.inspect(sample))); Let me know and I will change on github.

martin

28 April 2015

Hi Chris, sorry it has taken me so long to respond to your question. Node-red doesn't have any underlying issues with Binary data, it all comes down to how you want to handle the data. I believe the DEBUG node just does a basic string conversion on the data object before printing. I my set up I was just sending regular ascii strings to the XBEE coordinator. If you want to send something else you would have to parse out msg.payload in JavaScript to get what you want.

Waldo C

28 April 2015

Thanks! I left all my setup back in the office, but I will test it first thing tomorrow morning and let you know.

Waldo C

29 April 2015

It works. Thanks a lot for you help and for putting up this node! It will be very helpful for my project. best wishes!

martin

29 April 2015

Thanks for letting me know. Glad it worked for you. I have an experimental version of this node updated and packaged as an NPM running on my server. When I get some time I will finish testing and publish to npmjs.com. Keep an eye out for it!

martin

29 April 2015

Waldo, which GitHub repository did you pull this node from? I want to make sure I update the right one.

Waldo C

29 April 2015

The one in this same page. https://github.com/freakent/NR-XBee.git Again, many thanks! Best wishes!

Reece Robinson

01 May 2015

Hi, I was hoping I could use this node to send hex formatted xbee frames using this node-red component. I can successfully send "Hello World" text using it but I can't send an xbee frame e.g. 7E 00 10 17 01 00 13 A2 00 40 3B B1 BB FF FE 02 44 34 05 CF which will set D4IO to High on the associated End Device. Am I missing something?

martin

01 May 2015

You are quite right, I only built support for sending strings. That was all I needed for my purposes. Feel free to make the necessary changes and send me a pull request :-) How are you constructing the frames in node-red?

Reece Robinson

02 May 2015

I have added a new node for setting the digital output state of xbee pins to your code however I don't know how to create a pull request?

martin

02 May 2015

Thee are some pretty simple instructions on GitHub. https://help.github.com/articles/creating-a-pull-request/

Reece Robinson

02 May 2015

Done :-)

Renan

04 May 2015

is there a new release of this project ? I ask because when running my application, I got these message from the log file: node-red-0 (err): connections property is deprecated. Use getConnections() method Thanks!

martin

22 May 2015

Renan, I pushed a version up to Github at the start of the month. However I am not sure where that error is coming from, there is nothing in the code of this module that calls a connections property.

Mike Girdner

21 August 2016

I am not a Linux expert but I have played with Node Red for a while now. I tried to follow your instructions to install the XBee node but they are not showing up in the Node Red left pane. Any suggestions on what I should look for next? Any help would be appreciated.

José Luiz

24 March 2017

Hi, I am trying to send a remote AT command to a remote XBee to put D5 output on HIGH. A used a function Node before XBeeOUT Node as bellow , but I am receiving the error: TypeError: Object [object Object] has no method 'replace' Please Could any one give me same directions about what is wrong. I will appreciate some help. ThankYou and regards msg.destination = "0013A200406FB7C4"; msg.topic = "REMOTE_AT_COMMAND_REQUEST"; msg.payload = { type: "REMOTE_AT_COMMAND_REQUEST", command: "D5", remoteCommandOptions: 0x02, commandParameter: [0x05] }; return msg;