Reading RSSI from received API frame of XBee on Arduino

-1

as usual with last hope, kindly help me, I am trying to read the RSSI of a received packet of XBee with API mode, all I have done is as below,

XBee S2 (both configured as API-2)

Coordinator API
DH - 0 DL - FFFF

Router API
DH - 0 DL - 0

I am sending a this frame from Router as

#include <XBee.h>
#include <SoftwareSerial.h>
  SoftwareSerial softwareSerial (4,5);
  XBee xbee = XBee();

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

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

At the coordinator as a receiving node I am trying to read the RSSI with the following code

#include <XBee.h>
#include <SoftwareSerial.h>    
SoftwareSerial softwareSerial (4, 5);    
XBee xbee=XBee();
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();
uint8_t rssi = 0; 

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

void loop() {
  xbee.readPacket();
  if (xbee.getResponse().isAvailable()) {
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        xbee.getResponse().getRx64Response(rx64);;
        rssi = rx64.getRssi();
        Serial.println(rssi);
    }
  }
}   

While executing these programs, I am getting RSSI value which remains constant, means it does not changes by moving the Router away from Coordinator or taking it near, which should not be like that. Please point me towards where I am trying to reach.

As I am searching everywhere, I got this code at many place upon the internet which show the following code, that doesn't even show me anything in my case, I am posting it just for those who have Idea about it.

void loop() 
{
  xbee.readPacket();
  if (xbee.getResponse().isAvailable()) {
    if(xbee.getResponse().getApiId() == RX_16_RESPONSE || xbee.getResponse().getApiId() == RX_64_RESPONSE) {   
      if (xbee.getResponse().getApiId() == RX_64_RESPONSE) {
        xbee.getResponse().getRx64Response(rx64);;
        rssi = rx64.getRssi();
        Serial.println(rssi);
      } 
      else {
        xbee.getResponse().getRx16Response(rx16);;
        rssi = rx16.getRssi();
        Serial.println(rssi);
        }
    }
  }
}
arduino
arduino-uno
arduino-ide
xbee
asked on Stack Overflow Mar 9, 2020 by Jawad Khan • edited Mar 11, 2020 by tomlogic

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0