Example XBee Serial Device

From Digi Developer

Jump to: navigation, search



This DIA example implements a device driver for a fictitious wind turbine controller. It is aimed at illustrating how to parse a stream of serial data transmitted wirelessly from an XBee RS-232 Adapter, XBee RS-485 Adapter, or an XBee module in a development board or custom embedded design.

The device presumes that a wind turbine controller is connected to an XBee module and streaming a serial data. The DIA driver's job is to receive and parse this stream of serial data into a set of channel properties. The wind turbine controller provides three data points of information that we wish to capture:

  1. The number of revolutions per minute the turbine is turning
  2. The number of kilowatts generated instantaneously by the turbine
  3. The temperature in Celsius reported by a sensor at the top of the turbine

Each complete sentence of data is newline-delimited and each individual data point in a sentence is colon-delimited. All data points are represented as ASCII strings. An example of the data stream is the following:



You should register at www.digi.com/products/cloud/digi-device-cloud and then download DIA. After that, read the Getting Started guide. You should have a basic working knowledge of the DIA (how to start and stop drivers and presentations) before proceeding.

Driver Design

The basic design methodology of a driver is as follows:

  1. Decide what settings and channel preperties are needed, add them to the driver initialization section.
  2. Review which XBee configuration blocks are being set by this driver, adjust them as needed.
  3. Add custom DD values to src/devices/xbee/common/prodid.py
    NOTE: program remote device XBee DD values to match in order to allow your device to be automaticalyl enumerated by xbee_autoenum.py. The most-significant 16 bits should match your module type (0x0003 is ZigBee) while the least-nignificant 16-bits may be set to the range 0xff00-0xffff and are reserved for private use by customers.
  4. Accumulate serial data into a receive parse buffer, parse sentences from this buffer.
  5. When complete sentences are found, update the driver's channel properties.


Download the below Python source file. This file is intended solely for reference sake. Read over the file including all comments and Python doc strings.

Personal tools
Wiki Editing