XBee origin address in Arduino
I am trying to find a way to get the origin address of an XBee radio in Arduino.
Basically, I want my XBee chip to send a string that also contains its origin address (or id) so th开发者_如何转开发at I can identify where the message is coming from without having to run different code on every different Arduino.
What should I do?
EDIT
I am using the xbee-arduino library (http://code.google.com/p/xbee-arduino/).
The xbee is connected directly to the Arduino through a Sparkfun Xbee Shield (http://www.sparkfun.com/products/9976)
It is communicating with a Connectport X2 running XIG (http://code.google.com/p/xig/) so I can't run any arduino code on there that would look at the sender's address - it has to be found locally on the board.
I believe that what you're looking for is the Serial Number of the XBee, which is a globally unique, 64-bit address that identifies that device.
There are two AT commands available, SH and SL, that give you the high and low 32 bits of the serial number. There's an example program in the xbee-arduino distribution that prints their values: AtCommand.pde
That program then executes the AI command, which returns a byte giving the status of the last network join request. That will return 0x00
on success.
A ZigBee device also has a 16-bit address (use the MY command), which is only guaranteed to be unique on its network. With XBee modems on a stable network, that won't change unless there's an address conflict, but you will probably be better off using the full 64-bit value as determined with SH and SL.
All of these commands assume that the XBee that interests you is connected directly to the Arduino. They can all be executed remotely using RemoteATCommand
, but that requires you to pass the serial of the remote modem, so if you can successfully make the call then you already had the address.
If the XBee you're interested in is not connected to the Arduino, then you'll need to use the ND (Node Discover) command to perform a network scan. I'm not familar enough with the xbee-arduino API to know if they make that available, but getting the information about each node as it's discovered requires a little more work.
If you are using the API mode on these XBee chips (sure, if you use the XBee-api library), you do not need to include the address of the sender in the message. This information is automatically specified in the frame. Have a look at the getRemoteAddress16() and getRemoteAddress64() methods in class ZNetRxBaseResponse.
So what you have to do, is send a first message "hello" i.e. to the Coordinator (which you can address easily as 0x0000) from the Node you want to know the address. Using the above mentioned methods you can get this information.
精彩评论