Read Xbee Address

Looking for a way to read an XBee Address or ID using an Arduino so that I can uniquely identify where a string is originating from without having to have a separate program installed on each Arduino.

Has anyone done this before? Is it possible?

Brian

Sure is. I use S2 XBees in API mode with Andrew Rapp's library. Goes something like this here...

#include <XBee.h>              //http://code.google.com/p/xbee-arduino/
ZBTxRequest zbTx;
ZBRxResponse rx = ZBRxResponse();
...
zbTx.setAddress64(rx.getRemoteAddress64());    //return to sender
zbTx.setAddress16(0xFFFE);

Thanks. I have started looking at the API. However, since I am sending from an Arduino to a Connectport X2, I can't have arduino code running on the Connectport (ZB Coordinator) to return the senders address.

I need to find a way to get the address from within the local board. Does that make sense?

Looking for a way to read an XBee Address or ID using an Arduino so that I can uniquely identify where a string is originating from without having to have a separate program installed on each Arduino.

You could upload a sketch to the Arduino that stores a string in EEPROM. Change the string for each Arduino. Then, upload the sketch that the Arduino should run for real, that gets the string from EEPROM, and prepends it to any string sent.

bpmccain:
Thanks. I have started looking at the API. However, since I am sending from an Arduino to a Connectport X2, I can't have arduino code running on the Connectport (ZB Coordinator) to return the senders address.

I need to find a way to get the address from within the local board. Does that make sense?

Sure, use ATSH and ATSL to get the 64-bit address, or ATMY to get the 16-bit address. The latter is only unique within the network, but I'd think that'd be good enough for a lot of purposes.

PaulS also makes a good suggestion, I do something similar, only I use the XBee Node Identifier. I set a unique NI in each XBee, then the program interrogates it and inserts it into the transmitted data.

I set a unique NI in each XBee, then the program interrogates it and inserts it into the transmitted data.

How do you do this? A code snippet, please.

Hope this isn't too snipped up. I use X-CTU to set the NI (and also AP=2). The getXBeeNI() function gets called once from setup(). The readXBee() function gets called from loop() continuously to check for incoming traffic, and has a switch statement to check for various incoming packet types, one of which is a response to AT commands.

#include <XBee.h>              //http://code.google.com/p/xbee-arduino/
XBee xbee = XBee();                                       //XBee object

void getXBeeNI(void) {
    union {byte B; char C;} atCmd[3];
    AtCommandRequest atCmdReq;

    strcpy(&atCmd[0].C, "NI");
    atCmdReq = AtCommandRequest(&atCmd[0].B);
    xbee.send(atCmdReq);
}

void readXBee(void) {
    
    AtCommandResponse atResp;
    union {byte B; char C;} xbeeNI[9];                     //XBee node identifier
    byte respLen, *resp;

    xbee.readPacket();
    if (xbee.getResponse().isAvailable()) {                //incoming traffic
    
        switch (xbee.getResponse().getApiId()) {           //what kind of packet did we get?
    
        case ZB_RX_RESPONSE:                               //rx data packet
        ...
        case ZB_TX_STATUS_RESPONSE:						   //tx status
		...        
        case AT_COMMAND_RESPONSE:                          //response to AT commands
            atResp = AtCommandResponse();
            xbee.getResponse().getAtCommandResponse(atResp);
            if (atResp.isOk()) {
                respLen = atResp.getValueLength();
                resp = atResp.getValue();
                for (int i=0; i<respLen; i++) {
                    xbeeNI[i].B = resp[i];
                }
                xbeeNI[respLen].B = '\0';
                Serial.print(millis(), DEC);
                Serial.print(" XBee NI=");
                Serial.println(&xbeeNI[0].C);
            }
            else {
                Serial.println("XBee AT CMD ERROR");
            }
            break;

Hope this isn't too snipped up.

It's fine. Thanks. I'll have to have another look at the XBee library. When I have time...