How to read XBee RSSI in API mode?

0

I am trying to test a XBee RSSI in API mode at receiving end, how can I retrieve the RSSI value of the receiving radio in arduino.
I configured both XBee in API-2 mode and are connected to arduino by pin 4-5(rxtx & txrx) to Xbee radios.

Sending frame code is like below and there is no problem in transmission at both ends,

  uint8_t data[] = {'H','i'};
  XBeeAddress64 addr64 = XBeeAddress64();
  addr64.setMsb(0x00000000); // Msb address of receiver
  addr64.setLsb(0x00000000); // Lsb address of receiver
  ZBTxRequest zbTx = ZBTxRequest(addr64, data, sizeof(data));
  xbee.send(zbTx); 
  delay(1000);

At the receiving end I tried pulseIn of arduino and .getRssi() of , The former function gives "0" in result while the later gives "102" but remains the same as I move the Xbee radios away from each other. What should I need to do for getting correct RSSI at the receiving end..?

arduino
xbee
asked on Stack Overflow Mar 11, 2020 by Jawad Khan • edited Mar 11, 2020 by tomlogic

1 Answer

0

Hopefully this answer helps you and others.
Assuming you are using the following lib: https://github.com/andrewrapp/xbee-arduino
and you have a series 1 module you can use the following test code for quick diagnostics. the commented parts can of course also be used if needed

#include <XBee.h>
#include <SoftwareSerial.h>

// XBee's DOUT (TX) is connected to pin 8 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 9 (Arduino's Software TX)
SoftwareSerial serial1(8, 9); // RX, TX

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();

// uint8_t xbeeOption = 0;
// uint8_t xbeeData = 0;
uint8_t xbeeRssi = 0;

void setup() {
  Serial.begin(9600);
  serial1.begin(9600);
  xbee.setSerial(serial1);
}

void loop() {
  xbee.readPacket(100);
  if (xbee.getResponse().isAvailable())  {
    Serial.println("Xbee available");
    if (xbee.getResponse().getApiId() == RX_64_RESPONSE || xbee.getResponse().getApiId() == RX_16_RESPONSE)  {
      Serial.println("64 or 16");
      if (xbee.getResponse().getApiId() == RX_16_RESPONSE)  {
        Serial.println("16");
        xbee.getResponse().getRx16Response(rx16);
        // xbeeOption = rx16.getOption();
        //Serial.print("xbeeOption: "); Serial.println(xbeeOption);
        //xbeeData = rx16.getData(0);
        //Serial.print("xbeeData: "); Serial.println(xbeeData);
        xbeeRssi = rx16.getRssi();
        Serial.print("xbeeRssi: "); Serial.println(xbeeRssi);
      }
      else  {
        Serial.println("64");
        xbee.getResponse().getRx64Response(rx64);
        //xbeeOption = rx64.getOption();
        //Serial.print("xbeeOption: "); Serial.println(xbeeOption);
        //xbeeData = rx64.getData(0);
        //Serial.print("xbeeData: "); Serial.println(xbeeData);
        xbeeRssi = rx64.getRssi();
        Serial.print("xbeeRssi: "); Serial.println(xbeeRssi);
      }
    }
  }

If you use a series2 module there is only the way using the hardware pwm signal: In order for the RSSI pwm signal to be updated it needs to have received an API packet. Also, for the series 2 Xbee this applies only for the last hop of the packet, so from last router to destination. You need to use the XBee rssi pin and some coding depending on your appliance.
The rssi for distance is not very reliable and you will see a change perhaps every 10 to 15 meters while sending packets. So just moving a Xbee around on your workplace will not change the values.
EDIT: When using a series 2 module there is the following possibility: connect the rssi pin of the xbee (6) to an Arduino pwm pin (eg 10) and measure the incoming signal, which could then be mapped to a quality or/and distance range. So writing your own rssi function. The usual xbee libs only support series1 modules.

answered on Stack Overflow Mar 11, 2020 by Codebreaker007 • edited Mar 12, 2020 by Codebreaker007

User contributions licensed under CC BY-SA 3.0