Problem getting the RSSI (DB) from an Xbee

Good evening everyone! :smiley:

I am currently working on a project in which i must obtain the RSSI value from the messages arriving to an incoming xbee. So, in order to do that, i have decided to use AT Commands (by firstly sending the +++ and them the ATDB). Here is the code:

#include <XBee.h>
#include <SoftwareSerial.h>
// First element for Xbee Tx (Arduino RX)
// Second element for Xbee Rx (Arduino Tx)
SoftwareSerial xbee(3, 2);
int rssi;
String message;

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

  delay(1000);
  xbee.print("+++");
  delay(1000);
  
  
  if(xbee.available())
  {   
      //Read the OK and empty the buffer
      while(xbee.available())
      {
        Serial.write(xbee.read());
      }
      
      xbee.println("ATDB");

      rssi = xbee.read();
      Serial.print(rssi);
      Serial.println();
   
  } 
}

So for the output, i am getting the OK response from the xbee. However, when i attempt to read the rssi value i get the -1 for no data available instead of the 0 (the inital value for the DB parameter of a device who has not yet received any messages). I am not sending the command properly? Shouldn’t i expect the parameter value to come in through the serial port?

Thank you for your time and for reading this post :slight_smile:
Also thanks in advance for the help

  xbee.print("+++");
  delay(1000);

How long does the XBee stay in this mode?

      xbee.println("ATDB");

      rssi = xbee.read();

Exactly how long have you given the Arduino to shift the data out to the XBee AND for the XBee to recognize the command AND for the XBee to generate a response AND for the response to get back to the Arduino?

Come on. I want to know NOW!

Hi Paul thanks for the reply :smiley: !

I just checked the datasheet the default time for the AT command mode is 10 seconds. But i believe it can be ended prematurely with ATCT.

Yes! I guess i will try adding a delay between sending the command and reading the response from the Xbee. I will test it out soon! (as i am really not waiting anything at all)

I just checked the datasheet the default time for the AT command mode is 10 seconds.

I’m glad you checked. I was thinking it was one second.

Thank you Paul it is working perfectly now! I will post the full working code here in case somebody has a similar problem.

#include <XBee.h>
#include <SoftwareSerial.h>
// First element for Xbee Tx (Arduino RX)
// Second element for Xbee Rx (Arduino Tx)
SoftwareSerial xbee(3, 2);
int rssi;
int firstB;
String message;

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

  firstB = 0;
  
  if(xbee.available())
  {   
      //We check the first to see if the data is truly an incoming message
      firstB = xbee.read();
  
      //We start our messages with M, ACII 77
      //If this was a message start the loop!!!    
      if( firstB == 77)
      {
        //Read the incoming message
        while(xbee.available())
        {
          Serial.write(xbee.read());
        }
        Serial.println();
      
        //Setting it to command mode
        delay(1000);
        xbee.print("+++");
        delay(1000);

        //Read the OK confirmation
        while(xbee.available())
        {
          Serial.write(xbee.read());
        }
        Serial.println();
      
        //Add a delay to wait for the response
        xbee.println("ATDB");
        delay(100);

        //Read the DB parameter stored in the xbee
        Serial.print("The rssi value is: ");
        while(xbee.available())
        {
          Serial.write(xbee.read());
        }
        Serial.println();
      
        //Exit command mode
        xbee.println("ATCN");
      }
  } 
}

Hello. I confused with the connection between arduino and xbee. can u explain it to me? thanks