Programming Xbee modules in Linux using Ruby::XBee

Ruby::XBee (open source) allows you to configure and access the Digi XBee RF devices using ruby classes and ruby-based command line utilities.

Limitations

Not all XBee features are supported, though many are.

No provision is made to flash new device firmware into the XBee from Ruby::XBee classes or utilities.

Intel architecture only.

Digi does offer a Linux version of the XCTUNG and XBee Studio that can be used for programming the XBee modules with.

Quick Start

Install ruby for your platform (see www.ruby-lang.org)

Download the ruby-xbee tarball. There are several options depending on your product and desired interface:  https://rubygems.org/search?query=Ruby+xbee

tar xvfz ruby-xbee-.tar.gz

Create a symbolic link for serial-port-1.2.1:

ln -s ruby-serial-port-1.2.1-linux-intel ruby-serialport-1.2.1

determine your /dev string and add it to the conf/xbeeconfig.rb file.

Once the XBIB-CU USB device or similar XBee Interface board is plugged into the USB port on the Linux host, the in-kernelftdi driver should automatically load and create the associated device. It is usually /dev/ttyUSB0 for the first USB host port, with additional ports incrementing (i.e. /dev/ttyUSB1, /dev/ttyUSB2). The first host serial port is typically labeled /dev/ttyS0, with additional ports incrementing (i.e. /dev/ttyS1, /dev/ttyS2, etc...).

Sample entry for the USB XBIB-CU device:


 

# this is the monitor port device # your device will be different than this #@xbee_usbdev_str = "/dev/tty.KeySerial1" @xbee_usbdev_str = "/dev/ttyUSB0"

Sample entry for the Serial XBIB-R-DEV:

# this is the monitor port device

# your device will be different than this

#@xbee_usbdev_str = "/dev/tty.KeySerial1"

@xbee_usbdev_str = "/dev/ttyS0"

Test communication:

./xbeeinfo.rb

If everything is configured correctly you will see output from xbeeinfo similar to this (your output will vary):

$ ./xbeeinfo.rb Attention:

OK Firmware: 10CD
Hardware: 180B
Baud: 9600
Parity: None
Neighbors: [{:NI="BMW528", :MY="2", :SH="13A200", :SL="4008A642", :DB=-36}]
Node ID: Base
Station Channel: C PAN ID: 1 MY: 1 SH: 13A200 SL: 4008A64E DH: 0 DL: 2
Last received signal strength (dBm): -36
Port 0: Disabled
Port 1: DI
Port 2: Disabled
Port 3: Disabled
Port 4: Disabled
Port 5: Associated_Indicator
Port 6: Disabled
Port 7: CTS
Port 8: Disabled

Configuring an XBee using Ruby and the Ruby::XBee class

Syntax ./xbeeconfigure.rb [options]

Command line help

./xbeeconfigure.rb --help 


 

Example usage:

./xbeeconfigure.rb --nodeid BaseStation --panid 01 --mysrc 01 -H0 -L 2 -s

The command above configures a Digi XBee 802.15.4 with a human readable node ID of BaseStation, a PAN ID of 1, sets the devices MY 16-bit source address to 1, sets the destination to point to an XBee in a 16-bit addressing mode with a low address of 2 (-L 2) and a high of 0 which determines this is a 16-bit address.) Finally, the -s causes the new configuration to be saved in the Digi XBee flash when the configuration is completed. The BaseStation node id is reported as one of the attributes from neighboring nodes.

Since there are both long and short versions of the same options, an equivalent, shorter command line is:

./xbeeconfigure.rb -n BaseStation -M 01 -M 01 -H0 -L 2 -s

Learn More:

You can learn more about Ruby::XBee and other projects at: https://rubygems.org/gems/ruby-xbee

Last updated: Jul 30, 2024

Filed Under

RFRF Dev kits

Recently Viewed

No recently viewed articles

Did you find this article helpful?