Working on Zigbee API mode interface

Since 4 weeks i have a Digi XStick. This is a USB module that provides connectivity to a XBee network:

XStick

XStick

This XStick ZB is configured to behave as a coordinator within a mesh topology. The XStick can be plugged directly into the USB port of a PC and doesn’t require batteries or power adapter since it’s USB powered. Last 2 weeks i’ve been working on a Zigbee interface for my domotica system, using ths XStick.

First some things you need to know..

An Xbee module has three communication modes:

  • Transparent mode,
  • Command mode
  • API mode.

At startup, an Xbee module is in transparent mode. In this mode, the module acts as a serial line replacement. All data received from the DIN pin is transmitted, and when RF data is being received, it is sent out on the DOUT pin. A pair of XBee modules can act as invisible cables in this mode.

Command mode is where you can change a large amount of settings of the XBee module. To enter Command mode you must send the characters “+++” and wait a second. Once the XBee enters command mode, it will answer with OK. Most of us will remember this behavior from modems. While in command mode you can change baud rate, destination address, etc etc. Leaving command mode can be accomplished by executing the ATCN command.

Sending messages to constantly changing targets (=other XBee modules), API mode is the best mode to choose. It is the most powerfull but also the most complicated mode to use. API (Application Programming Interface) mode is a frame-based method for sending and receiving data to and from an XBee.

API mode has some special abilities:

  • Changing parameters without entering command mode;
  • RSSI and source address information;
  • Receive packet delivery confirmation on every transmitted packet

Since API mode seems to be the most flexible, i decided to create an API-mode interface. With more then 140 pages of  information of how to interface with XBee/XBee-PRO ZB RF modules i knew this was a job that could take a while, but today i managed to get a sequence of API mode commands working.

The first command i started with  was the Node Discovery command, which will let every device on the network respond with basic information about that device. These reponses are received by the XStick, the address information of the responding XBee devices is stored and the next step is to send a request to all of the responding devices to request information about their hardware version. Today i succeeded in doing this first excercise, as you can see here:

Execute Node Discovery
Sending frame:7E 00 04 08 01 4E 44 64
Serialport.RxCount:33
RxBuffer:7E 00 1D 88 01 4E 44 00 86 23 00 13 A2 00 40 31 B9 04 45 44 41 54 32 00 00 00 02 00 C1 05 10 1E 12

*** Processing frame ***
ApiID = 88
Checksum Ok=True

ATCommandResponse, 29 bytes:
FrameID=1
Command=ND
Status=0
MY 8623
SH,SL 5526146518202628 (0013A2004031B904)
NI [EDAT2]
PARENT 00 00
DEVICE_TYPE 02
STATUS 00
PROFILE_ID C1 05
MANUFACTURER_ID 10 1E

Request Hardware Version for Node 8623
Sending frame:7E 00 0F 17 01 00 13 A2 00 40 31 B9 04 86 23 00 48 56 BD
Serialport.RxCount:21
RxBuffer:7E 00 11 97 01 00 13 A2 00 40 31 B9 04 86 23 48 56 00 19 44 E0

*** Processing frame ***
ApiID = 97
Checksum Ok=True

RemoteATCommandResponse, 17 bytes:
FrameID=1
Command=HV
Status=0
Response=19 44

So the XBee module that responded has a Hardware Version of 1944 🙂

Tagged , . Bookmark the permalink.

15 Responses to Working on Zigbee API mode interface

  1. Saad says:

    Hi there,

    I am doing a school project on this and I cannot figure out how to get the xbee in API mode running :-(. What did you use to view the above output?? What is XStick? I put the XBEE modules (2) on two arduino boards. Please Help. Email me at lpsaad@gmail.com. Thanks!

    • Hi Saad,

      To get the XBee (Series 2) into API mode, use the X-CTU tool to write the right firmware to the XBee. That’s it, basically..
      I wrote my own software to be able to create, send, receive and process API packets.
      So what you’re seeing is output from my own software which is part of my Domotica (Home Automation) system.

      The XStick is a USB peripheral module adapter that provides short-range wireless connectivity to an XBee network. I use it as an API mode Coordinator.

  2. YogiBear75 says:

    Hi there,

    I would like to know where you buy this stuff. As it seems you bought a lot of Xbee modules and the cheapest Pro’s I could find were like $40 ?

    Or do you have a secret source ?

    Thanks,

    Yogi.

  3. Pingback: Wireless Pressure Sensor - small fix

  4. Dan says:

    Is there a notable speed difference between API and AT command mode? Obviously it needs to send more data, I am thinking of setting up a wireless sensor that would need to be very fast and wondering if it would be faster to pack my own frames or use the API mode.

    • Hi Dan,

      I really can’t tell you, since i hardly used AT command mode. Maybe the first evening, getting familiar with some of the basic AT commands to set baud rate and such. But after that i switched to API mode rather quickly cause that looked like the most suitable command mode in my case.

  5. Jacob says:

    Could you share your delphi code with me? I really would like to avoid making a wrapper my self

    • Hi Jacob,

      Sorry my response took so long, i had other matters that needed my attention.
      I could share my Delphi code, but it’s mixed with code from the rest of my Domotica system. So i don’t think it will be of much help to you. The best i can do is give you a link to the .NET Micro Framework Toolkit i used as a starting point. It’s written in C#, but it should be relatively easy to translate to Delphi. That’s what i did and it took me about 2-3 evenings, so it’s not that hard to do 🙂
      Good luck!

  6. Trino says:

    Can you please tell me the following hex code :
    7E 00 04 08 01 4E 44 64 ?

  7. Anuj Sanghavi says:

    I am trying to find RSSI values from Co-ordinator to different routers attached to it. I am using Xbee pro S2b. My co-ordinatir is attached to an Arduino due with Wireless sd shield. I am able to serial communicate with my co-ordinator using AT commands. When I send ND as an AT command it gives all the information of different routers attached to it. But I don’t know how can I get the RSSI values from different Routers.

Leave a Reply

Your email address will not be published. Required fields are marked *