trouble ACK and get size packet received with xbee S2C

Hi, im from indonesia. sorry if my english is bad
I have a problem to confirm that the packet on the receiver side is acknowledged and sender always get deliverystatus = success, even though packet not receive

Sender Code

#include <XBee.h>
#include <SoftwareSerial.h>
// create the XBee object
XBee xbee = XBee();
SoftwareSerial xb(2, 3); // RX, TX
// we are going to send two floats of 4 bytes each
uint8_t payload[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
union u_tag {
    float f1,f2;
    int adc,adc1,s,m,h;
    uint8_t b[4];
} value;
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x41630C48);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
float voltage,volt;
float ntu;
int statusLed = 13;
int errorLed = 13;
void setup() {
   Serial.begin(9600); //Baud rate: 9600
   pinMode(statusLed, OUTPUT);
   //xbee.begin(Serial);
   //xbee.begin(xb);  
   xbee.setSerial(Serial);
}
void loop() {
   int sensorpH = analogRead(A0);// read the input on analog pin 0:
   int sensorTurbidity = analogRead(A1);// read the input on analog pin 0:
   voltage = sensorTurbidity * (5.0 / 1024); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
   volt = sensorpH * (5.0 / 1024);
   ntu = 100 - (voltage/4.16)*100.00;    //4.16
   float Po = 7 + ((2.5 - volt) / 0.18); //0.357
   Serial.print("ADC ");
   Serial.print(sensorTurbidity);
   Serial.print(" ADC pH ");
   Serial.print(sensorpH); // print out the value you read:
   Serial.print(" Turbidity ");
   Serial.print(ntu);
   Serial.print("%");
   Serial.print(" pH ");
   Serial.println(Po,3);
   if (!isnan(sensorTurbidity) && !isnan(sensorpH)) {
      // convert value sensor float into a byte array and copy it into the payload array
      value.adc = sensorpH;
      for (int i=0;i<4;i++){
          payload[i]=value.b[i];
      }
      // sama juga dengan diatas
      value.adc1 = sensorTurbidity;
      for (int i=0;i<4;i++){
          payload[i+4]=value.b[i];
      }
      int s=1;
      int m=30;
      int h=12;
      /*
      value.f1 = ntu;
      for (int i=0;i<4;i++){
          payload[i+8]=value.b[i];
      }
      value.f2 = Po;
      for (int i=0;i<4;i++){
          payload[i+12]=value.b[i];
      }
      */
      payload[8]=h >> 8 & 0xff;
      payload[9]=h & 0xff;
      payload[10]=m >> 8 & 0xff;
      payload[11]=m & 0xff;
      payload[12]=s >> 8 & 0xff;
      payload[13]=s & 0xff;
      xbee.send(zbTx);
      flashLed(statusLed, 1, 100);
      // after sending a tx request, we expect a status response
      // wait up to half second for the status response
      xbee.readPacket(5000);
      if (xbee.getResponse().isAvailable()) {
          // got a response!
          // trx packet from xbee to variable         
          if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
              xbee.getResponse().getZBTxStatusResponse(txStatus);
              if (txStatus.getDeliveryStatus() ==   SUCCESS) {
                  // success.  time to celebrate
                  Serial.println("Packet send has been success");
                  flashLed(statusLed, 1, 500);
              }  
              else {
                  // the remote XBee did not receive our packet. is it powered on?
                  flashLed(errorLed, 3, 500);
                  Serial.println ("Packet not sending");
              }
          }
          else if (xbee.getResponse().isError()) {
              Serial.println("Error reading packet.  Error code: ");  
              Serial.println(xbee.getResponse().getErrorCode());
          }
      }          
   }
   delay(2000);
}
void flashLed(int pin, int times, int wait) { 
   for (int i = 0; i < times; i++) {
       digitalWrite(pin, HIGH);
       delay(wait);
       digitalWrite(pin, LOW);   
       if (i + 1 < times) {
          delay(wait);
       }
   }
}

Receiver Code

#include <Printers.h>
#include <XBee.h>
#include <string.h>
#include <SoftwareSerial.h>
//initialises the data array with 0
uint8_t payload[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
//
XBee xbee = XBee();
// create reusable response objects for responses we expect to handle 
ZBRxResponse zbRx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
//XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x41554A03);
unsigned long start, finished, elapsed;
char ValAdc[4];
char ValAdc1[4];
char n[4];
char no[4];
char noo[4];
int index,rx,loss;

typedef struct {
  float volt = 0.0f;//voltage
  float ntu = 0.0f; //turbidity
  int adc,adc1;
  int h,m,s; //integer var  
} load;
load theData;

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

// continuously reads packets, looking for ZB Receive or Modem Status
void loop()
{
   // 1. This will read any data that is available:
   xbee.readPacket();
   // 2. Now, to check if a packet was received: 
   index++;
   Serial.print("index ");
   Serial.println(index);
   if (xbee.getResponse().isAvailable())
   {
      rx++;
      Serial.print("packet receive ");
      Serial.println(rx);
      // got packet from xbee
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
      {
          // trx packet from xbee to variable
          xbee.getResponse().getZBRxResponse(zbRx);
          if (zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
              // the sender got an ACK
              //flashLed(statusLed, 10, 100);
              Serial.println("packet acknowledged");
          } 
          else {
              // we got it (obviously) but sender didn't get an ACK
              //flashLed(errorLed, 2, 100);
              Serial.println("packet not acknowledged");
          }
          for(int i = 0; i < 14; i++){
              payload[i] = zbRx.getData(i);
          }  
          ValAdc[0]= zbRx.getData(0);
          ValAdc[1]= zbRx.getData(1);
          ValAdc[2]= zbRx.getData(2);
          ValAdc[3]= zbRx.getData(3);
          memcpy(&theData.adc, &ValAdc, 4);
          ValAdc1[0]= zbRx.getData(4);
          ValAdc1[1]= zbRx.getData(5);
          ValAdc1[2]= zbRx.getData(6);
          ValAdc1[3]= zbRx.getData(7);
          memcpy(&theData.adc1, &ValAdc1, 4);
          //n[0] = zbRx.getData(8);
          //n[1] = zbRx.getData(9);
          byte un1,un2,un3,un4,un5,un6;
          un1 = zbRx.getData(8);
          un2 = zbRx.getData(9);
          un3 = zbRx.getData(10);
          un4 = zbRx.getData(11);
          un5 = zbRx.getData(12);
          un6 = zbRx.getData(13);
          //memcpy(&theData.h, &n, 2);
          //no[0] = zbRx.getData(10);
          //no[1] = zbRx.getData(11);
          //memcpy(&theData.m, &no, 2);
          //n2[0] = zbRx.getData[10];
          //n2[1] = zbRx.getData[11];
          
          //byte unsecond5 = zbRx.getData[12];
          //byte unsecond6 = zbRx.getData[13];
          Serial.print("Turbidity : ");
          Serial.print(theData.adc1);
          Serial.print(" pH: ");
          Serial.print(theData.adc);
          Serial.print(" waktu ");
          Serial.print(word(un1,un2)); 
          Serial.print(":");
          Serial.print(word(un3,un4)); 
          Serial.print(":");
          Serial.print(word(un5,un6)); 
          Serial.print(" Size ");
          Serial.println(sizeof(payload));        
      } else {
           Serial.print("No data getting out of the packet");    
      }
      /*  
      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) {
              // status xbee terhubung flashLed(statusLed, 10, 10);
              Serial.println("xbee associated");
           } else if (msr.getStatus() == DISASSOCIATED) {
                // status xbee tidak terhubung flashLed(errorLed, 10, 10);
                Serial.println("xbee disassociated");
           } else {
              // another status flashLed(statusLed, 5, 10);
              Serial.println("Unknown trouble");
           }
      }*/  
   }
   else if (xbee.getResponse().isError()){
       Serial.print("oh no!!! error code:");
       Serial.println(xbee.getResponse().getErrorCode());      
   }
   else
   {
       loss++;
       Serial.print("packet loss ");
       Serial.println(loss);
   }  
   if (index==100) {
      Serial.print("PLR=");
      int total=index-rx;
      Serial.println(total);
   }
   delay(1500);
}// END OF LOOP
union u_tag {
    float f1,f2;
    int adc,adc1,s,m,h;
    uint8_t b[4];
} value;

All of the things in a union should be the same size.

2 floats is 8 bytes, not 4.
2 floats is 4 ints, not 5.
5 ints is 10 bytes, not 4.

   int sensorTurbidity = analogRead(A1);// read the input on analog pin 0:

That is NOT what that code does. If you are going to have useless comments, make them correct useless comments.

      // convert value sensor float into a byte array and copy it into the payload array
      value.adc = sensorpH;
      for (int i=0;i<4;i++){
          payload[i]=value.b[i];
      }

The adc member of the union is an int, not a float.

Are you using Serial to talk to the XBee or to talk to the PC? Both is the wrong answer. So is yes.

      // wait up to half second for the status response
      xbee.readPacket(5000);

Half of 1000 is not 5000.

PaulS:

union u_tag {

float f1,f2;
    int adc,adc1,s,m,h;
    uint8_t b[4];
} value;



All of the things in a union should be the same size.

2 floats is 8 bytes, not 4.
2 floats is 4 ints, not 5.
5 ints is 10 bytes, not 4.



int sensorTurbidity = analogRead(A1);// read the input on analog pin 0:



That is NOT what that code does. If you are going to have useless comments, make them correct useless comments.



// convert value sensor float into a byte array and copy it into the payload array
      value.adc = sensorpH;
      for (int i=0;i<4;i++){
          payload[i]=value.b[i];
      }



The adc member of the union is an int, not a float.

Are you using Serial to talk to the XBee or to talk to the PC? Both is the wrong answer. So is yes.



// wait up to half second for the status response
      xbee.readPacket(5000);



Half of 1000 is not 5000.

sorry for miss comment.

So, the correct variabel like this ?

//zero for iniator is 18 because 2 float,5 int.
uint8_t payload[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
union u_tag {
    float f1,f2;
    int adc,adc1,s,m,h;
    uint8_t bI[2],bF[4];
} value;

and for storing to payload like this

      // convert value sensor int into a byte array and copy it into the payload array
      value.adc = sensorpH;
      for (int i=0;i<2;i++){
          payload[i]=value.bI[i];
      }
      value.adc1 = sensorTurbidity;
      for (int i=0;i<2;i++){
          payload[i+2]=value.bI[i];
      }
      value.f1 = ntu;
      for (int i=0;i<4;i++){
          payload[i+4]=value.bF[i];
      }
      value.f2 = Po;
      for (int i=0;i<4;i++){
          payload[i+8]=value.bF[i];
      }
      value.h = h;
      for (int i=0;i<2;i++){
          payload[i+12]=value.bI[i];
      }
      value.m = m;
      for (int i=0;i<2;i++){
          payload[i+14]=value.bI[i];
      }
      value.s = s;
      for (int i=0;i<2;i++){
          payload[i+16]=value.bI[i];
      }

whether I should measure the content packet or content packet + frame from delimiter 0x7e till checksum byte ?
i want measure for packet loss,delay and throughtput. what should i do.

how to confirm is this function worked, in my case always get ack on receiver or packet loss
zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED

The payload array does NOT have to be of type unit8_t. If your payload is two ints, declare the array accordingly.

   int payload[2];

   payload[0] = sensorPH;
   payload[1] = sensorTurbidity;

If your payload is a mix of types, define a struct:

   struct s
   {
      float ntu, Po;
      int sensorPH, sensorTurbidity, s, m, h;
   } anInstance;

Populate it:

   anInstance.ntu = ntu;
   anInstance.pO = Po;
   anInstance.sensorPH = sensorPH;
   anInstance.sensorTurbidity = sensorTurbidity;
   anInstance.s = s;
   anInstance.m = m;
   anInstance.h = h;

Tell the XBee to send the struct as the payload:

ZBTxRequest zbTx = ZBTxRequest(addr64, (uint8_t *)anInstance, sizeof(struct s));

PaulS:
The payload array does NOT have to be of type unit8_t. If your payload is two ints, declare the array accordingly.

   int payload[2];

payload[0] = sensorPH;
  payload[1] = sensorTurbidity;




If your payload is a mix of types, define a struct:


struct s
  {
      float ntu, Po;
      int sensorPH, sensorTurbidity, s, m, h;
  } anInstance;




Populate it:


anInstance.ntu = ntu;
  anInstance.pO = Po;
  anInstance.sensorPH = sensorPH;
  anInstance.sensorTurbidity = sensorTurbidity;
  anInstance.s = s;
  anInstance.m = m;
  anInstance.h = h;




Tell the XBee to send the struct as the payload:


ZBTxRequest zbTx = ZBTxRequest(addr64, (uint8_t *)anInstance, sizeof(struct s));

Ok, for matter type data. Now i want to know why im always receive delivery status always get success(value=0) even though packet not received on coordinator.

if (txStatus.getDeliveryStatus() ==   SUCCESS) {
                  // success.  time to celebrate
                  Serial.println("Packet send has been success");
                  flashLed(statusLed, 1, 500);
              }  
else {
                  // the remote XBee did not receive our packet. is it powered on?
                  flashLed(errorLed, 3, 500);
                  Serial.println ("Packet not received"); 
       }

My serial monitor on sender always print ("Packet send has been success") except if my xbee coordinator off then print ("Packet not received")

receiver code

xbee.readPacket();
if (xbee.getResponse().isAvailable())
{
         //packet receive
         if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
         {
              // trx packet from xbee to variable
              xbee.getResponse().getZBRxResponse(zbRx);
              if (zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
                  // the sender got an ACK
                  Serial.println("packet acknowledged");
              } 
               else {
                     // we got it (obviously) but sender didn't get an ACK
                     Serial.println("packet not acknowledged");
               }
         }
         else {
               Serial.print("Packet received but not same with API ID header frame");  //is this same packet loss  
         }
}
else {
           Serial.print("No data getting out of the packet");    
}

You haven't answered the question in reply #1. Until you do, we can't make progress.

PaulS:
Are you using Serial to talk to the XBee or to talk to the PC? Both is the wrong answer. So is yes.

Can you tell me what diference using serial to talk to xbee or to talk to the pc ?
if my perception not wrong then i'm use xbee to talk to pc with xbee shield on arduino. my coordinator xbee receive data from end device and transfered to web for monitoring network status and value sensor. after that i want perform QoS multihop with mesh network xbee.

Sorry if a lot do not i understand. if you can explain to me, it helps me a lot

Can you tell me what diference using serial to talk to xbee or to talk to the pc ?

If you are using the Serial instance to allow the XBees to communicate, the ONLY thing that should be send over the Serial instance is well-formed packets. All that other crap you are Serial.print()ing is confusing the hell out of the XBees.

PaulS:
If you are using the Serial instance to allow the XBees to communicate, the ONLY thing that should be send over the Serial instance is well-formed packets. All that other crap you are Serial.print()ing is confusing the hell out of the XBees.

then how i can communicate with xbee to pc not via serial. and i want get report well-formed packet has been received on coordinator and sending to database and viewed to localhost web

You have a desk phone and a cell phone. You need to call a business to order some supplies and your girlfriend (or boyfriend) to arrange a date.

Are you REALLY going to set up a conference call? THAT is what you are doing now.

Use one phone to call the business. Use the other phone to call the friend.

If your Arduino doesn't have more than one hardware serial port, you can:

  1. Get a different Arduino
  2. Use SoftwareSerial

PaulS:
You have a desk phone and a cell phone. You need to call a business to order some supplies and your girlfriend (or boyfriend) to arrange a date.

Are you REALLY going to set up a conference call? THAT is what you are doing now.

Use one phone to call the business. Use the other phone to call the friend.

If your Arduino doesn't have more than one hardware serial port, you can:

  1. Get a different Arduino
  2. Use SoftwareSerial

PaulS:
i'm using five arduino uno with xbee shield for my task school, so i can't change to different arduino. if i want use software serial, do i need buy xbee adapter usb for coordinator ?

f i want use software serial, do i need buy xbee adapter usb for coordinator ?

No. You just change a switch position or move some jumpers, depending on which XBee shield you are using. Of course, you need to change the code, too.

my attachment picture xbee shield im using (Xbee Expansion Shield V03).

of the many examples I can get on the internet using the library softwareserial, why i can't use command
xbee.begin(9600); and using xbee adapter for coordinator.
SoftwareSerial xb(2, 3); // RX, TX
so i'm confused, there no examples using xbee shield

You need to look at the traces on that board. Does the XBEE/USB switch switch between pins 0 and 1 and pins 2 and 3?

If it does, post your code using SoftwareSerial. In the code you posted earlier, you had xbee.SetSerial(Serial). In your code with SoftwareSerial actually being used, do you still call SetSerial()? With what as the argument?

i want send data from end device to coordinator via router.
end >> router 3 > router 2 >> router 1 >> coordinator.
my config xbee s2c mode api
PAN ID 123
coordinator SH 13A200 SL 41630C48 DH 0 DL FFFF api mode 1
end dev SH 13A200 SL 41554A03 DH 13A200 DL 41630C api mode 2
router 1 SH 13A200 SL 41554A05 DH 0 DL 0 api mode 2
router 2 SH 13A200 SL 41673405 DH 0 DL 0 api mode 2
router 3 SH 13A200 SL 41630C4B DH 0 DL 0 api mode 2

here my source code for point to point success but how to forward via router.
coordinator

#include <XBee.h>
#include <string.h>
#include <SoftwareSerial.h>
#include <DS3231.h>
#include <Wire.h>
#include <time.h>

XBee xbee = XBee();
//SoftwareSerial xb(2, 3); // RX, TX

//initialises the data array with 0 
uint8_t payload[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
// create reusable response objects for responses we expect to handle 
ZBRxResponse zbRx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

DS3231  rtc(SDA, SCL); // Init the DS3231 using the hardware interface
const int rtcpin = 3;
char f1[4];
char f2[4];
char ms[4];
byte t1,t2; // variable for uniting typedata int
long Start,End, timeqos, qMS; //variable count time difference
int qH,qM,qS; //variable qos time
int rec,loss;
int dataJam,dataMenit,dataDetik; // variable for current time
volatile unsigned long current_millis;
unsigned long millisecond;
int index=0;
float plr;
float totdelay = 0.0f;
float deltadelay = 0.0f;
Time waktu;

typedef struct {
  float pH = 0.0f;//pH
  float ntu = 0.0f; //turbidity
  int h,m,s; //hour minute second
  unsigned long ms;
} load;
load theData;

void setup()
{
   Serial.begin(9600);
   rtc.begin();
   pinMode(rtcpin, INPUT_PULLUP);
   attachInterrupt(1, rtc_interrupt, FALLING);
   rtc.setOutput(0);
   rtc.setSQWRate(1); 
   //xb.begin(9600);
   //xbee.setSerial(xb);
   xbee.begin(Serial);
   Serial.println("ready");
   delay(250);
}

void qos(bool c){
   index++;
   if (c){
       rec++;
       Serial.println("Qualit of Service ");
       Serial.print("Packet Loss ");
       Serial.print(loss);
       Serial.print(" Packet Received ");
       Serial.print(rec);
       Serial.print(" Total Packet ");
       Serial.println(index);
       Start=dataJam*3600+dataMenit*60+dataDetik;
       End=theData.h*3600+theData.m*60+theData.s;
       timeqos=Start-End;
       qH=timeqos/3600;
       timeqos=timeqos-qH*3600;
       qM=timeqos/60;
       timeqos=timeqos-qM*60;
       qS=timeqos;
       qMS=qS*1000+(millisecond-theData.ms);
       totdelay=totdelay+(qMS/1000.0);   
       Serial.print("Time Elapsed ");
       Serial.print(qMS);
       Serial.print(" ms ");
       //float te = qMS/1000.0;
       //Serial.print("Time Sec ");
       //Serial.print(te,2);
       Serial.print("Throughput ");
       float thg = 240.0/(qMS/1000.0);
       Serial.print(thg,2);
       Serial.print(" Bps ");
       Serial.print("PLR ");
       plr = ((float) loss/(float)index) *100.0;
       Serial.print(plr);
       Serial.print(" % ");
       deltadelay = totdelay/rec;
       Serial.print("Delay ");
       Serial.println(deltadelay);
   } else {
       loss++; 
       Serial.print("Packet Loss ");
       Serial.print(loss); 
       Serial.print(" Packet Received ");
       Serial.print(rec); 
       Serial.print(" Total Packet ");
       Serial.println(index);     
   }
}

void print32Bits(uint32_t dw){
  print16Bits(dw >> 16);
  print16Bits(dw & 0xFFFF);
}


void printDigits(int digits)
{
    // utility function for digital clock display: prints preceding colon and leading 0
    Serial.print(':');
    if(digits < 10)
        Serial.print('0');
    Serial.print(digits);
}

void print8Bits(byte c){
  uint8_t nibble = (c >> 4);
  if (nibble <= 9)
    Serial.write(nibble + 0x30);
  else
    Serial.write(nibble + 0x37);
      
  nibble = (uint8_t) (c & 0x0F);
  if (nibble <= 9)
    Serial.write(nibble + 0x30);
  else
    Serial.write(nibble + 0x37);
}

void rtc_interrupt() // this updates every second.
{
  current_millis++;
  if (current_millis ==  999) //roll over to zero
      current_millis =0;
}

void loop()
{
   // 1. This will read any data that is available:
   xbee.readPacket();
   waktu = rtc.getTime();
   // 2. Now, to check if a packet was received:
   if (xbee.getResponse().isAvailable())
   {
      Serial.print("Frame Type is ");
      Serial.println(xbee.getResponse().getApiId(), HEX);
      // got packet from xbee
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
      {
          // trx packet from xbee to variable
          Serial.print("Got an rx packet from: ");
          XBeeAddress64 senderLongAddress = zbRx.getRemoteAddress64();
          print32Bits(senderLongAddress.getMsb());
          Serial.print(" ");
          print32Bits(senderLongAddress.getLsb());
          Serial.println();
          xbee.getResponse().getZBRxResponse(zbRx);
          if (zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
              Serial.println("packet acknowledged");
          } 
          else {
              // we got it (obviously) but sender didn't get an ACK
              Serial.println("packet not acknowledged");
          }
             dataJam = waktu.hour;     
             dataMenit = waktu.min;
             dataDetik = waktu.sec;
             millisecond = current_millis;
          f1[0]= zbRx.getData(0);
          f1[1]= zbRx.getData(1);
          f1[2]= zbRx.getData(2);
          f1[3]= zbRx.getData(3);
          memcpy(&theData.ntu, &f1, 4);
          f2[0]= zbRx.getData(4);
          f2[1]= zbRx.getData(5);
          f2[2]= zbRx.getData(6);
          f2[3]= zbRx.getData(7);
          memcpy(&theData.pH, &f2, 4);
          t1 = zbRx.getData(8);
          t2 = zbRx.getData(9);
          theData.h = word(t1,t2);
          t1 = zbRx.getData(10);
          t2 = zbRx.getData(11);
          theData.m = word(t1,t2);
          t1 = zbRx.getData(12);
          t2 = zbRx.getData(13);
          theData.s = word(t1,t2);
          ms[0]= zbRx.getData(14);
          ms[1]= zbRx.getData(15);
          ms[2]= zbRx.getData(16);
          ms[3]= zbRx.getData(17);
          memcpy(&theData.ms, &ms, 4);
          Serial.print("Turbidity : ");
          Serial.print(theData.ntu);
          Serial.print(" pH : ");
          Serial.println(theData.pH);
          Serial.print("Time Sender ");
          Serial.print(theData.h); 
          Serial.print(":");
          printDigits(theData.m); 
          Serial.print(":");
          printDigits(theData.s); 
          Serial.print(":");
          Serial.println(theData.ms); 
          Serial.print("Time Receive ");
          Serial.print(dataJam); 
          Serial.print(":");
          printDigits(dataMenit); 
          Serial.print(":");
          printDigits(dataDetik); 
          Serial.print(":");
          Serial.println(millisecond); 
          Serial.print("Packet length is ");
          Serial.print(zbRx.getPacketLength(), DEC);
          Serial.print(", data payload length is ");
          Serial.print(zbRx.getDataLength(),DEC); 
          Serial.print(" checksum is ");
          Serial.println(zbRx.getChecksum(), HEX);   
          Serial.println("Received Data: ");
          for (int i = 0; i < zbRx.getDataLength(); i++) {
          //for (int i = 0; i < zbRx.getPacketLength(); i++) {
          //print8Bits(zbRx.getDataLength()[i]);
          print8Bits(zbRx.getData()[i]);
          Serial.print(' ');}
          Serial.println();
          qos(true);
      } else {
           Serial.print("No data getting out of the packet");    
      }     
   }
   else if (xbee.getResponse().isError()){
       Serial.print("error code:");
       Serial.print(xbee.getResponse().getErrorCode());
       if (xbee.getResponse().getErrorCode()==1){
          Serial.println(" Checksum error");      
       } else 
       if (xbee.getResponse().getErrorCode()==3){
          Serial.println(" Unexpected Start Byte"); 
       }
   }
   else {
       qos(false);
   }
   delay(500);
}// END OF LOOP

end device

#include <XBee.h>
#include <SoftwareSerial.h>
#include <DS3231.h>
#include <Wire.h>
#include <time.h>

DS3231  rtc(SDA, SCL);
// create the XBee object
XBee xbee = XBee();
//SoftwareSerial xb(2, 3); // RX, TX
// we are going to send 18 bytes
uint8_t payload[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
union u_tag {
    float f1,f2;
    unsigned long ms;
    uint8_t b[4];
} value;

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x41630C4B);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

const int rtcpin = 3;
float volt1,volt2;
float ntu,Ph;
int statusLed = 13;
int errorLed = 13;
int h,m,s;
volatile unsigned long current_millis;
unsigned long elapsed_millis;
unsigned long prev_millis=0;
unsigned long interval=1000;
Time waktu;

void setup() {
   Serial.begin(9600); //Baud rate: 9600
   rtc.begin();
   pinMode(rtcpin, INPUT_PULLUP);
   attachInterrupt(0, rtc_interrupt, FALLING);
   //attachInterrupt(1, rtc_interrupt, FALLING);
   rtc.setOutput(0);
   rtc.setSQWRate(1);
   pinMode(statusLed, OUTPUT);
   xbee.begin(Serial);
   //xb.begin(9600);
   //xbee.setSerial(Serial);  
   //rtc.setTime(23,17,0);
}

void rtc_interrupt() // this updates every second.
{
  //current_millis=millis();
  current_millis++;
  if (current_millis ==  999) //roll over to zero
      current_millis =0;
}

void loop() {
   waktu = rtc.getTime();
   h = waktu.hour;     
   m = waktu.min;
   s = waktu.sec;
   int sensorpH = analogRead(A0);// read the input on analog pin 0:
   int sensorTurbidity = analogRead(A1);// read the input on analog pin 1:
   volt1 = sensorTurbidity * (5.0 / 1024); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
   volt2 = sensorpH * (5.0 / 1024);
   ntu = 100 - (volt1/4.16)*100.00;    //4.16
   Ph = 7 + ((2.5 - volt2) / 0.18); //0.357
   /*
   Serial.print("ADC ");
   Serial.print(sensorTurbidity);
   Serial.print(" ADC pH ");
   Serial.print(sensorpH);*/ 
   Serial.print(" Turbidity ");
   Serial.print(ntu);
   Serial.print("%");
   Serial.print(" pH ");
   Serial.print(Ph,3);
   Serial.print(" Time ");
   Serial.print(h); 
   Serial.print(":");
   Serial.print(m); 
   Serial.print(":");
   Serial.print(s); 
   Serial.print(":");
   Serial.println(current_millis);
   
   value.f1 = ntu;
   for (int i=0;i<4;i++){
          payload[i]=value.b[i];
   }
   value.f2 = Ph;
   for (int i=0;i<4;i++){
          payload[i+4]=value.b[i];
   } 
   payload[8]=h >> 8 & 0xff;
   payload[9]=h & 0xff;
   payload[10]=m >> 8 & 0xff;
   payload[11]=m & 0xff;
   payload[12]=s >> 8 & 0xff;
   payload[13]=s & 0xff;
   value.ms = current_millis;
   for (int i=0;i<4;i++){
          payload[i+14]=value.b[i];
   } 
   xbee.send(zbTx);
   // after sending a tx request, we expect a status response
   if(xbee.readPacket(1000)){
    
   flashLed(statusLed, 5, 100);
   if (xbee.getResponse().isAvailable()) {
       // got a response!
       // trx packet from xbee to variable         
       if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
           xbee.getResponse().getZBTxStatusResponse(txStatus);
           if (txStatus.getDeliveryStatus() ==   SUCCESS) {
               // success.  time to celebrate
               Serial.println("Packet send has been success");
               flashLed(statusLed, 1, 500);
           }  
           else {
                // the remote XBee did not receive our packet. is it powered on?
                flashLed(errorLed, 3, 500);
                Serial.println ("Packet not sending");
                }
        }
        else if (xbee.getResponse().isError()) {
              Serial.println("Error reading packet.  Error code: ");  
              Serial.println(xbee.getResponse().getErrorCode());
        }
    } }
}

void flashLed(int pin, int times, int wait) { 
   for (int i = 0; i < times; i++) {
       digitalWrite(pin, HIGH);
       delay(wait);
       digitalWrite(pin, LOW);   
       if (i + 1 < times) {
          delay(wait);
       }
   }
}
   xbee.begin(Serial);
   Serial.println("ready");

       Serial.println("Qualit of Service ");
       Serial.print("Packet Loss ");
       Serial.print(loss);
       Serial.print(" Packet Received ");
       Serial.print(rec);
       Serial.print(" Total Packet ");
       Serial.println(index);

  if (nibble <= 9)
    Serial.write(nibble + 0x30);
  else
    Serial.write(nibble + 0x37);

   xbee.readPacket();
   waktu = rtc.getTime();
   // 2. Now, to check if a packet was received:
   if (xbee.getResponse().isAvailable())
   {

Are you using Serial to talk to the PC OR to talk to the Arduino? Both is the wrong answer. So is yes.

PaulS:

   xbee.begin(Serial);

Serial.println("ready");

Serial.println("Qualit of Service ");
      Serial.print("Packet Loss ");
      Serial.print(loss);
      Serial.print(" Packet Received ");
      Serial.print(rec);
      Serial.print(" Total Packet ");
      Serial.println(index);

if (nibble <= 9)
    Serial.write(nibble + 0x30);
  else
    Serial.write(nibble + 0x37);

xbee.readPacket();
  waktu = rtc.getTime();
  // 2. Now, to check if a packet was received:
  if (xbee.getResponse().isAvailable())
  {



Are you using Serial to talk to the PC OR to talk to the Arduino? Both is the wrong answer. So is yes.

im using serial for talk to arduino for serial monitoring, progress sending,receive and view data.
what do you think I should do to see the data received for analysis. if there some example for it that very helpful

You have a PC that you want to talk to. Think of that as your wife.

You have an XBee you want to talk to. Think of that as your girlfriend.

Do you REALLY want to talk to your wife and girlfriend at the same time, on the same phone line?

If you persist in that folly, I see a divorce in your future. Or a murder.

PaulS:
You have a PC that you want to talk to. Think of that as your wife.

You have an XBee you want to talk to. Think of that as your girlfriend.

Do you REALLY want to talk to your wife and girlfriend at the same time, on the same phone line?

If you persist in that folly, I see a divorce in your future. Or a murder.

i want xbee talk to xbee from end dev to coordinator, if data received on coordinaor i want to view it on pc. how to make xbee talk and pc not at the same time ? how do i get to see the data received if not Serial.print on coordinator? okay i will delete Serial.print(); then how to store data received on coordinator xbee+arduino to pc on mysql ? is it there some example please.