Pages: [1]   Go Down
Author Topic: Read Xbee Address  (Read 950 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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);
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4084
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
#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;
« Last Edit: September 27, 2011, 06:35:43 am by Jack Christensen » Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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...
Logged

Pages: [1]   Go Up
Jump to: