EmbeddedRelated.com
Forums

XBee network discovery in API mode

Started by "rai...@ymail.com [rabbit-semi]" February 4, 2016
Hi all,

This is not directly rabbit related (yet)... since for the moment I'm playing with the xbee modules all connected on a windows pc though usb-serial adaptors. I want to play with them and see what's happening with my own eyes :) Then, I'll have some rabbit targets for them.

All in all, I set up a network with 3 modules, one coordinator and 2 routers. Everything works very well (and I tested A LOT...).

I only have one little problem: the ND command in API mode seems to not work as expected.
First, in AT mode it works ok. It generates two groups of network info for the two routers, exactly as documented in the manual.
In API mode however, I'm receiving only one 0x88 frame with the first router info, and a 0xA1 frame with the address of the second router (and two zero bytes at the end that I can only guess what's the meaning)

Here is the first frame (a 0x88 one): (with my debugging messages)
API Frame received:
88 01 4E 44 00 23 08 00 13 A2 00 40 B2 49 50 45 54 48 32 33 32 49 4F 34 00 FF FE 01 00 C1 05 10 1E
AT cmd response: ND
status: 0
data:
23 08 00 13 A2 00 40 B2 49 50 45 54 48 32 33 32 49 4F 34 00 FF FE 01 00 C1 05 10 1E
NI indicator content:
address: 2308:0013A20040B24950
NI: ETH232IO4
parent: FFFE
device type: 1

source event: 0

And then the second frame (a 0xA1 one):
API Frame received:

A1 00 13 A2 00 40 E5 78 C9 F6 20 00 00
My note here: the address is correct for the second router. The last two zeros may mean something like: no options (first byte) and zero addresses (the second byte) although this is just a guess.

There is more: if I insist of doing ND commands repeatedly, I will get sometimes 0x88 frames with the second router info! But always a SINGLE FRAME, not two.

It seems to me that the ND command in API mode is not very robust. At least I cannot find a good documentation for it (in API mode). In AT mode it seems that it works very well though.

Now, I have two solution:
1. Switch to AT mode and deal with the ND only in AT mode - that only for the ND command
2. Just forget about ND - it's somewhat possible in my intended app - although the ND is quite nice to have and more convenient.

Unless someone will make some light about it... :)

Thanks,
Raimond
Raimond,

For starters, if you haven't already started working with it, I recommend using the ANSI C XBee Host Library from GitHub. I wrote it while an employee at Digi, and it's the foundation of the XBee library in Dynamic C 10.72 and the Programmable XBee Development Kit.

https://github.com/tomlogic/xbee_ansic_library

Seeing your email reminds me that I should probably port changes to the library into the version included with Dynamic C.

So if you start developing code for your Windows PC, using that library, you should be able to port it to the Rabbit without too much difficulty.

The 0xA1 frame type is a "route record indicator". Odd that it would be coming in from that device as a response to the ND command. The two bytes are "receive_options" and "address_count", and then it'd be followed by 16-bit network addresses.

You'd have to refer to the documentation regarding when an XBee module sends an 0xA1 response.

What are you using as an ATNT value on the modules? That's the "Node Discovery Timeout" value. It should be the same on all devices -- if it's higher on the routers than the coordinator, then the router might be sending its response after the coordinator has timed out.

If you download that host library from GitHub, you'll find an API layer for managing node discovery. Take a look at the "transparent serial" sample -- it includes discovery and the ability to send data to discovered nodes.

Also, I recommend 115200bps for the serial connection to the XBee. Get data on and off of the module quickly so you don't have to mess around with buffering it on either end when sending at 9600 baud.

Hope that helps. Feel free to contact me off list (since this is "off topic" for now) if you have further questions.

-Tom
On Feb 4, 2016, at 7:36 AM, r...@ymail.com [rabbit-semi] wrote:

>
> Hi all,
>
> This is not directly rabbit related (yet)... since for the moment I'm playing with the xbee modules all connected on a windows pc though usb-serial adaptors. I want to play with them and see what's happening with my own eyes :) Then, I'll have some rabbit targets for them.
>
> All in all, I set up a network with 3 modules, one coordinator and 2 routers. Everything works very well (and I tested A LOT...).
>
> I only have one little problem: the ND command in API mode seems to not work as expected.
>
> First, in AT mode it works ok. It generates two groups of network info for the two routers, exactly as documented in the manual.
>
> In API mode however, I'm receiving only one 0x88 frame with the first router info, and a 0xA1 frame with the address of the second router (and two zero bytes at the end that I can only guess what's the meaning)
>
> Here is the first frame (a 0x88 one): (with my debugging messages)
>
> API Frame received:
>
> 88 01 4E 44 00 23 08 00 13 A2 00 40 B2 49 50 45 54 48 32 33 32 49 4F 34 00 FF FE 01 00 C1 05 10 1E
>
> AT cmd response: ND
>
> status: 0
>
> data:
>
> 23 08 00 13 A2 00 40 B2 49 50 45 54 48 32 33 32 49 4F 34 00 FF FE 01 00 C1 05 10 1E
>
> NI indicator content:
>
> address: 2308:0013A20040B24950
>
> NI: ETH232IO4
>
> parent: FFFE
>
> device type: 1
> source event: 0
>
> And then the second frame (a 0xA1 one):
>
> API Frame received:
> A1 00 13 A2 00 40 E5 78 C9 F6 20 00 00
>
> My note here: the address is correct for the second router. The last two zeros may mean something like: no options (first byte) and zero addresses (the second byte) although this is just a guess.
>
> There is more: if I insist of doing ND commands repeatedly, I will get sometimes 0x88 frames with the second router info! But always a SINGLE FRAME, not two.
>
> It seems to me that the ND command in API mode is not very robust. At least I cannot find a good documentation for it (in API mode). In AT mode it seems that it works very well though.
>
> Now, I have two solution:
>
> 1. Switch to AT mode and deal with the ND only in AT mode - that only for the ND command
>
> 2. Just forget about ND - it's somewhat possible in my intended app - although the ND is quite nice to have and more convenient.
>
> Unless someone will make some light about it... :)
>
> Thanks,
>
> Raimond
>
Thank you Tom,

The problem is solved, I was just loosing the second frame because my debugging messages were too long...
Now everything is ok, I'm receiving a 0x88 frame for every router.

About your library, I new of it, looks pretty good, but I have a problem with this kind of libraries: I prefer to write my own :D

Seriously, for this kind of library, the documentation should me a lot more extensive. Something like the tcp/ip manual (three volumes). Or, at least making a combo manual with the current xbee manual content interleaved with the library functions. Something like a hybrid doc with both hardware/protocol related description AND the library implementation. Otherwise the user should read both docs separately and should make the connections by himself.

I took your advice and setup the modules to 115200.

And as a little observation: the manual says that the modules are in API mode by default (ATAP=1). This is nor the case, all my modules came with ATAP=0. Probably this is a little documentation slip.

Thanks again,
Raimond