Analyzing sensor readings with an XBee wireless connection

XBee Networks

The ZigBee protocol makes it possible to span a variety of network topologies ranging from simple connections that exist between two partners to large networks consisting of tens of thousands of participants (Figure 4). The firmware for the XBee module takes care of the details. The developer only has to distribute roles and create the addresses for the network.

Figure 4: The XBee supports extremely diverse network topologies, which in turn make a variety of application scenarios possible.

An XBee module assumes the role of coordinator, router, or endpoint. Every network topology includes a coordinator that regulates communication among all of the participants. Routers separate network segments. The modules at the edge of the network function as communication endpoints. The simplest network consists of two modules that include one coordinator and a router or endpoint.

The module firmware determines the role that an XBee module will assume. The firmware is loaded in the module using an application provided by the manufacturer and is then configured. You can flash and configure the XBee module from Digi International with the configuration software XCTU [9]. The company has an introductory video [10] that provides an overview.

Configuration Software

The XBee module configuration software only exists for Windows and Mac OS X, so Linux users like me have to take a loop via Wine, which is available in most distros. The command

sudo yum install wine

installs the package under Fedora. More detailed instructions are set out in the "XCTU on Linux" box.

XCTU on Linux

After downloading XCTU, you should start installation as a user with administration rights by invoking:

$ sudo wine 40003002_C.exe

The setup installs the software in the user directory /root/.wine/drive_c/Program Files (x86)/Digi/XCTU-NG/. To start the program, switch into the installation directory and start XCTU.exe. The script from Listing 1 makes the procedure easier. Using

$ chmod 775 xctu

you can mark the script as executable. Thereafter, all you need to do is invoke sudo ./xctu.

XCTU accesses the serial interfaces, which are not installed automatically by Wine. Connecting a serial USB adapter to the PC creates the logical device name /dev/ttyUSB0 such that the last digit increases by one for each generated USB adapter (i.e., /dev/ttyUSB1, etc.). Wine requires you to link these devices to Wine in the /root/.wine/dosdevices directory:

$ sudo ln -s /dev/ttyUSB0 /root/.wine/dosdevices/com1

As a precautionary step, you should install three additional links for COM2 to COM4 at the same time. Now the serial ports have been prepared and are standing ready. At this point, it becomes necessary to make adaptations to the Wine configuration. This is done by using the Registry Editor to change the entries for the COM ports. You should add the path HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\SERIAL\COM\COM1 to COM port COM1. There you should create two strings. One of these is named ClassGUID and contains the content {4D36E978-E325-11CE-BFC1-08002BE10318}. You should enter Serial Port (COM1) in the second string, which is named FriendlyName. Setting up the other ports is accomplished in an analogous fashion, except that COM1 is replaced by COM2 and so forth. The contents of the string ClassGUID stays the same. This is simply the class designator for the serial ports.

Listing 1

XCTU Script

# Script: xctu
cd "/root/.wine/drive_c/Program Files (x86)/Digi/XCTU-NG/"

After starting XCTU, you should add the connected XBee modules to the configuration. One click on the symbol found to the left and above the Radio Modules column opens a dialog for selecting the COM port for connecting the module. The XBee modules transfer symbols with a standard port speed of 9600 baud. Clicking Finish loads the configuration module. Next, you should click in the left column on the entry of the indicated XBee module to open its configuration on the right side.

To load the module firmware that configures the coordinator, click on the Update Firmware symbol found above the configuration settings, where you select the coordinator firmware (Figure 5) that works with the module (e.g., version 1147 of ZNet 2.5 Coordinator API). The firmware is divided into AT and API versions. For additional details about these two firmware versions, see the "AT or API Firmware" box.

AT or API Firmware

The firmware is available in two forms: AT and API. The type of serial communication that occurs with the modules will depend on the selection of one or the other. A module operating in AT mode interprets incoming data like a modem as strings, and it executes so-called AT commands; for example, the command mode starts with the string +++. The string following this indicator is then executed as an AT command. For example, the command ATVR would return the firmware version. The AT mode is also called transparency mode. The XBee module sends all incoming data from the connections directly to the serial interface.

In API mode, the module interprets the data as structured blocks. Measurement values from the ports are packed into a data block that is then sent via the serial interface. The handbook describes the structure of these data blocks [12]. The first byte in a block is a start indicator (0x7E). The next two bytes specify the size of the block. The subsequent structure depends on the block type.

The console used to diagnose transmitted data is integrated in XCTU, and it is only available when the module connected to the PC is running in API mode. Therefore, it makes sense to operate the endpoint in AT mode and the coordinator in API mode.

Figure 5: Selecting the firmware loads the suitable software onto an XBee module.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content