Send and Receive Signal Strength via Xbee & Arduino

I have two Series 2 Xbee A and B connect to Arduino, and I am using the Xbee-Arduino-API.

My goal is to get the RSSI value from A to B through sending TX. Then, B can do readPacket and if found response of ZB_RX_Response, then I can know the signal strength via RSSI.

My approach of Sender:

  • Set up XBee address to broadcast TX
  • Set xbee_payload = {0, 0} since I don’t really care about the info.
XBeeAddress64 ALL_MAC = XBeeAddress64(0x0000,BROADCAST_ADDRESS);
ZBTxRequest xbee_tx = ZBTxRequest(ALL_MAC, xbee_payload, sizeof(xbee_payload));

Here is my code of Sender, Xbee A:

#include <Streaming.h>
#include <XBee.h>

XBee xbee = XBee();

// create an arbitrary payload -- what we're sending is not relevant
uint8_t payload[] = { 0, 0 };

// SH + SL Address of a remote XBee
/*
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x4093d45a);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
*/
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
ZBRxResponse rx = ZBRxResponse();


uint8_t xbee_payload[] = {0, 0};
// broadcasting 
XBeeAddress64 ALL_MAC = XBeeAddress64(0x0000,BROADCAST_ADDRESS);
ZBTxRequest xbee_tx = ZBTxRequest(ALL_MAC, xbee_payload, sizeof(xbee_payload));

void setup() {  
  // start XBee communication
  xbee.begin(9600);

}

void sendPacket() {
    xbee.send(xbee_tx);
}

void loop() {   
  sendPacket();
  
  delay(300);
  if(xbee.readPacket(500)) {
     Serial << "See response from xbee" << endl; 
  }
}

My Receiver, Xbee B:

#include <Streaming.h>
#include <XBee.h>

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

void setup() {
 
  xbee.begin(9600);
}

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
    
    xbee.readPacket();
    if (xbee.getResponse().isAvailable()) {
      // got something
      Serial << "Got Response" << endl;
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        // got a zb rx packet
        
        // now fill our zb rx class
        xbee.getResponse().getZBRxResponse(rx);
            
        if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
            // the sender got an ACK
           
        } else {
            // we got it (obviously) but sender didn't get an ACK
            
        }
        // set dataLed PWM to value of the first byte in the data
      } else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) {
        xbee.getResponse().getModemStatusResponse(msr);
        // the local XBee sends this response on certain events, like association/dissociation
        
        if (msr.getStatus() == ASSOCIATED) {
          // yay this is great.  flash led
          
        } else if (msr.getStatus() == DISASSOCIATED) {
          // this is awful.. flash led to show our discontent
          
        } else {
          // another status
          
        }
      } else {
      	// not something we were expecting
        
      }
    } else if (xbee.getResponse().isError()) {
      //nss.print("Error reading packet.  Error code: ");  
      //nss.println(xbee.getResponse().getErrorCode());
    }
}

However, my problem is that the receiver never get any Response. As you can see in my code, it didn’t get to print message:

Serial << "Got Response" << endl;

What I am understanding about TX and RSSI:

  • Use TX to send data via XBee
  • RSSI can detect radio frequency, and receive the info by using readPacket

Please explain to me because I really don’t understand the ZigBee protocol.

Try using
Serial.print(“Got Response \n”);

Please refer to attached file to read RSSI value of the packets received.

Hope it may helpful for you …

RSS.ino (2.54 KB)