+1 vote
4.0k views
in XBee by
How to print the address of the xbee that the message is sent from?

1 Answer

0 votes
by (1.3k points)
Please excuse for the unformated below. I'm just pasting bits which you can sort as needed I believe.

First init the needed as usual

XBee xbee                       = XBee();
        XBeeResponse response           = XBeeResponse();
        AtCommandRequest atRequest      = AtCommandRequest();
        AtCommandResponse atResponse    = AtCommandResponse();
        ZBRxResponse rx                 = ZBRxResponse();
        ZBTxRequest zbTx                = ZBTxRequest();
        ZBTxStatusResponse txStatus     = ZBTxStatusResponse();
        ModemStatusResponse msr                 = ModemStatusResponse();
        ZBRxIoSampleResponse ioSample     = ZBRxIoSampleResponse();

and in response block.... add the following

            XBeeAddress64 senderLongAddress = rx.getRemoteAddress64();
            print32Bits(senderLongAddress.getMsb());
            Serial.print(" ");
            print32Bits(senderLongAddress.getLsb());
            Serial.println(" ");

            uint16_t senderShortAddress = ioSample.getRemoteAddress16();
            Serial.print(" (");
            print16Bits(senderShortAddress);
            Serial.println(")");
            Serial.println("");

below are functions required for display

void print32Bits(uint32_t dw){
 print16Bits(dw >> 16);
 print16Bits(dw & 0xFFFF);
}

void print16Bits(uint16_t w){
 print8Bits(w >> 8);
 print8Bits(w & 0x00FF);
}

void print8Bits(byte c)
{
 uint8_t nibble = (c >> 4);
 if (nibble <= 9)
   Serial.write(nibble + 0x30);
 else
   Serial.write(nibble + 0x37);

 nibble = (uint8_t) (c & 0x0F);
 if (nibble <= 9)
   Serial.write(nibble + 0x30);
 else
   Serial.write(nibble + 0x37);
}

Related questions

0 votes
1 answer 1.2k views
asked Sep 24, 2021 in XBee by Sunder
0 votes
1 answer 1.8k views
+1 vote
1 answer 2.2k views
+1 vote
1 answer 1.4k views
...