Help Needed with programming to recieve data in API mode through XBEE.

I Have a Libelium Wasup Mote Plug and Sense, i'm sending analog data from three sensors namely carbon monoxide, nitrogen dioxide and oxygen to an arduino through xbee(Series 2), i can recieve the data when the xbee is connected to the pc directly, but couldnt read it through arduino, please help me with the code to recieve this data.

Both the Router and coordinator are in API mode, coordinator is connected to a arduino uno using a xbee sheild.
Thanks in advvance for your help.

but couldnt read it through arduino, please help me with the code to recieve this data.

No, thank you. YOU go first. What have you tried? What were the results?

hi,

i tried the code to recieve hex values, also tried the arduino code using a Xbee object in both these cases i dont receive anything, i have a blank serial monitor.

Well, if you won't share your code, or define how the XBee is connected to the Arduino, I can't help you. Good luck.

hi,

i have connected the zigbee( which is a series 2 xbee) to an arduino uno through a xbee shield, both my sender and reciever xbee's work at 115200 baud rate, and the code i used is as below.

void setup() {
  
  // start serial
  Serial.begin(115200);
  xbee.setSerial(Serial);
  
  
}

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
    
   if(Serial.available() >=21){
     if(Serial.read() == 0x7E){
       for (int i=1;i<19;i++){
         byte discardByte = Serial.read();
       }
       int analogMSB= Serial.read();
       int analogLSB = Serial.read();
       int temp = ((analogMSB+analogLSB)*0.513);
       
       Serial.print(temp);
     }}
}

i'm new to arduino and to arduino forum, pardon for any trouble i have caused.

through a xbee shield

There are at least three commonly used XBee shields that have little in common. I'm tired of guessing what you are doing.

hi paul,
i'm sorry to have troubled you, i'm using a xbee pro shield. i have attached the link for the xbee sheild below.

i want it to recieve ascii frames and display it for which i developed a new code which i have given below:

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

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();

// create reusable response objects for responses we expect to handle 
Rx64Response rx64 = Rx64Response();

uint8_t option = 0;
uint8_t* data = NULL;
uint8_t* rawData = NULL;

void setup() {
  
  // start serial

  
  Serial.begin(115200);
    xbee.setSerial(Serial);
    
  
  Serial.println("Arduino. Wait for packets.");

}

// continuously reads packets, looking for RX16 or RX64
void loop() {
    
    Serial.print(".");
    
    xbee.readPacket();
    
    if (xbee.getResponse().isAvailable()) {
      // got something
      
      if (xbee.getResponse().getApiId() == RX_64_RESPONSE) {
        // got a rx packet
        Serial.println("");
        Serial.println("RECEIVED");
        xbee.getResponse().getRx64Response(rx64);
        option = rx64.getOption();
        rawData = rx64.getFrameData();
        data = rx64.getData();
        
      
        Serial.println("raw data:");
        Serial.print("Ox");
          
        for (int i=0; i<rx64.getFrameDataLength(); i++) {

          Serial.print(rawData[i], HEX);
          Serial.print(" ");
        }
        
        Serial.println("");
        Serial.println("App data");
        Serial.print("Ox");
          
        for (int i=0; i<rx64.getDataLength(); i++) {

          Serial.print(data[i], HEX);
          Serial.print(" ");
        }
        Serial.println("");
        
        for (int i=0; i<rx64.getDataLength(); i++) {

          Serial.print((char)data[i]);
        }
        
        Serial.println("");
       
      } else if (xbee.getResponse().isError()) {
      //nss.print("Error reading packet.  Error code: ");  
      //nss.println(xbee.getResponse().getErrorCode());
      // or flash error led
      } 
  }
  
  delay(2000);
}

Since italics styled code isn't typically a feature of the Arduino programming environment, perhaps you should have started here:

How to use this forum - please read.

thanks for the information i changed it.

for which i developed a new code

Next question. Are you using Serial to talk to the XBee? Or are you using it to talk to the PC? Both is the wrong answer. So is yes.

hi paul,

is there a way to hook up the xbee avoiding the hardware serial port ?? because my xbee sheild doesnt have a switch, is there any other way to do this ?

is there a way to hook up the xbee avoiding the hardware serial port ?? because my xbee sheild doesnt have a switch, is there any other way to do this ?

Not with that shield. That thing is a piece of crap that should not be in anyone's toolbox. People still making them should be ashamed of themselves.

hi,
i bought a xbee explorer and connected the xbee to arduino using pin 10(as Rx) and 11 (as Tx), but i didnt get any data from the xbee, is there any error with the code i have attached below.

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



SoftwareSerial mySerial(10, 11); // RX, TX
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();

// create reusable response objects for responses we expect to handle 
Rx64Response rx64 = Rx64Response();
Rx16Response rx16 = Rx16Response();

uint8_t option = 0;
uint8_t* data = NULL;
uint8_t* rawData = NULL;

void setup() {
  
  // start serial

  Serial.begin(9600);
  mySerial.begin(115200);
    xbee.setSerial(mySerial);
    
  
  Serial.println("Arduino. Wait for packets.");

}

// continuously reads packets, looking for RX16 or RX64
void loop() {
    
    Serial.print(".");
    
    xbee.readPacket();
    
    if (xbee.getResponse().isAvailable()) {
      // got something
      
      if (xbee.getResponse().getApiId() == RX_64_RESPONSE) {
        // got a rx packet
        Serial.println("");
        Serial.println("RECEIVED");
        xbee.getResponse().getRx64Response(rx64);
        option = rx64.getOption();
        rawData = rx64.getFrameData();
        data = rx64.getData();
        
        
        Serial.println("raw data:");
        Serial.print("Ox");
          
        for (int i=0; i<rx64.getFrameDataLength(); i++) {

          Serial.print(rawData[i], HEX);
          Serial.print(" ");
        }
        
        Serial.println("");
        Serial.println("App data");
        Serial.print("Ox");
          
        for (int i=0; i<rx64.getDataLength(); i++) {

          Serial.print(data[i], HEX);
          Serial.print(" ");
        }
        Serial.println("");
        
        for (int i=0; i<rx64.getDataLength(); i++) {

          Serial.print((char)data[i]);
        }
        
        Serial.println("");
        
        if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
        // got a rx packet
        Serial.println("");
        Serial.println("RECEIVED");
        xbee.getResponse().getRx16Response(rx16);
        option = rx16.getOption();
        rawData = rx16.getFrameData();
        data = rx16.getData();
        
        
        Serial.println("raw data:");
        Serial.print("Ox");
          
        for (int i=0; i<rx16.getFrameDataLength(); i++) {

          Serial.print(rawData[i], HEX);
          Serial.print(" ");
        }
        
        Serial.println("");
        Serial.println("App data");
        Serial.print("Ox");
          
        for (int i=0; i<rx16.getDataLength(); i++) {

          Serial.print(data[i], HEX);
          Serial.print(" ");
        }
        Serial.println("");
        
        for (int i=0; i<rx16.getDataLength(); i++) {

          Serial.print((char)data[i]);
        }
        
        Serial.println("");
      } else if (xbee.getResponse().isError()) {
        
        Serial.print("Error reading packet.  Error code: ");
        Serial.println(xbee.getResponse().getErrorCode());
      //nss.print("Error reading packet.  Error code: ");  
      //nss.println(xbee.getResponse().getErrorCode());
      // or flash error led
      } 
     
      }
  
  
  delay(2000);
}
else {
  Serial.print ("No Data");
}
}

i can read the data through x-ctu software but couldnt read it through arduino, is it anything wrong with the code or is it any hardware issue ? i connected the xbee through a 5 pin xbee usb explorer, and the code for the frame creation in wasup mote xbee is as below,

// 9.1 Create new frame (No mote id)
  frame.createFrame(ASCII,"");  

  // 9.2 Add frame fields
  if( (XBEE_type != 2) && (XBEE_type < 4) )
  {
    // add low MAC address in the case it is not a DigiMesh firmware
    frame.addSensor(SENSOR_MAC, macLow);
  }
  frame.addSensor(SENSOR_ACC, ACC.getX(), ACC.getY(), ACC.getZ() );
  frame.addSensor(SENSOR_IN_TEMP, RTC.getTemperature());
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());

  // 9.3 Print frame
  // Example:<=>?#35690399##5#MAC:4066EF6B#ACC:-47;-26;1000#IN_TEMP:26.25#BAT:59#
  frame.showFrame();

  ////////////////////////////////////////////////
  // 10. Send the packet
  ////////////////////////////////////////////////

  if( XBEE_type == 4 ) 
  {
    USB.println(F("the frame above is printed just by USB (it is not sent because no XBee is plugged)"));  
  }

  if( XBEE_type < 4 ) 
  {
    // 10.1 set packet to send
    packet=(packetXBee*) calloc(1,sizeof(packetXBee)); // memory allocation
    packet->mode=BROADCAST; // set Unicast mode

    // 10.2 send the packet via the correct object depending on the protocol

    // case 802.15.4
    if (XBEE_type == 0) 
    { 
      // turn XBee on
      xbee802.ON();  
      // sets Destination parameters
      xbee802.setDestinationParams(packet, destination, frame.buffer, frame.length); 
      // send data
      xbee802.sendXBee(packet);

      // check TX flag
      if( xbee802.error_TX == 0 )
      {
        USB.println(F("the frame above was sent"));
      }
      else 
      {
        USB.println(F("sending error"));
      }    
    } 

    // case DM or 868/900
    if( (XBEE_type == 1) || (XBEE_type == 2) ) 
    {
      // turn XBee on
      xbeeDM.ON();
      // sets Destination parameters
      xbeeDM.setDestinationParams(packet, destination, frame.buffer, frame.length); 
      // send data
      xbeeDM.sendXBee(packet);

      // check TX flag
      if( xbeeDM.error_TX == 0 )
      {
        USB.println(F("the frame above was sent"));
      }
      else 
      {
        USB.println(F("sending error"));
      }
    }  

    // case ZB Router (not coordinator)
    if ((XBEE_type == 3) && (ZIGBEE_type > 0))
    { 
      // turn XBee on 
      xbeeZB.ON();

      // sets Destination parameters
      xbeeZB.setDestinationParams(packet, destination, frame.buffer, frame.length); 
      // send data
      xbeeZB.sendXBee(packet);

      // check TX flag
      if( xbeeZB.error_TX == 0 )
      {
        USB.println(F("the frame above was sent"));
      }
      else 
      {
        USB.println(F("sending error"));
      }
    }

    // 10.3 free memory
    free(packet);
    packet = NULL;
  }
  delay(1000);
}

this is the frame i want to recieve in arduino

but couldnt read it through arduino, is it anything wrong with the code or is it any hardware issue ?

If you know that the XBee is receiving data, because it gets to X-CTU, then you may have a hardware issue.

i bought a xbee explorer and connected the xbee to arduino using pin 10(as Rx) and 11 (as Tx)

What other connections did you make? Power? Ground?

Are they any lights blinking on the explorer as the XBee associates? Sends data? Receives data?

Hi
S i connected rx;tx; power and ground, s the xbee associates with the other xbee and the red and green led blinks; but the arduino is not reading the data.

You don't seem aware that we can NOT see your hardware. "the red and green led blinks" doesn't mean squat.

Just for giggles, try swapping the wires connected to pins 10 and 11 of the Arduino.

Hi
This is my hardware; i checked it with a new arduino uno but i still couldnt read the packet

i tried swapping the rx and tx but its still the same.