Zigbee Packet Loss

Hello all,

I am working on a project which aims to evaluate packet loss ratio in Zigbee-Arduino based network. What I know or I have done is that I configured two Zigbee S2 radios in API mode, one as a Router and other as Coordinator and connected them with microcontrollers.
As long as it is upto two nodes, i can achieve my objective by the following code.

Coordinator node have this code

#include <XBee.h>
// create the XBee object
XBee xbee = XBee();

int statusLed = 8;
int errorLed = 9;

int sendCounter = 0;
int successCounter = 0;
int lostCounter = 0;

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);
    }
  }
}

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

void loop() {   
 uint8_t data[] = {'H','I'};
  XBeeAddress64 addr64 = XBeeAddress64();
  addr64.setMsb(0x0013A200); //Msb address of router/end node
  addr64.setLsb(0x414E6D99); //Lsb address of router/end node 
  ZBTxRequest zbTx = ZBTxRequest(addr64, data, sizeof(data));
  ZBTxStatusResponse txStatus = ZBTxStatusResponse();

  xbee.send(zbTx);
 Serial.println();
 Serial.print("Sent Packets (" );
 Serial.print(sendCounter);
 Serial.print(")");

 Serial.println();
 Serial.print("Delivered Packets (" );
 Serial.print(successCounter);
 Serial.print(")");
 
 Serial.println();
 Serial.print("Lost Packets (" );
 Serial.print(lostCounter);
 Serial.print(")");
 

  // after sending a tx request, we expect a status response
  // wait up to half second for the status response
  if (xbee.readPacket(500)) {
    // got a response!

    // should be a znet tx status              
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);

      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        // success.  time to celebrate
        flashLed(statusLed, 5, 50);
        successCounter ++;
        
      } else {
        // the remote XBee did not receive our packet. is it powered on?
        flashLed(errorLed, 3, 500);
        lostCounter ++;
      }
    }
  } else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: ");  
    //nss.println(xbee.getResponse().getErrorCode());
    lostCounter ++;
    
  } else {
    // local XBee did not provide a timely TX Status Response -- should not happen
    flashLed(errorLed, 2, 50);
    lostCounter ++;
  }
  Serial.println();
  Serial.println();
  sendCounter ++;
  delay(2000);
}

Router node is

#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
void setup() {
  Serial.begin(9600);
  xbee.begin(Serial);
}
void loop() {
String sample;
  xbee.readPacket(); 
    if (xbee.getResponse().isAvailable()) {
      Serial.println(xbee.getResponse().getApiId());
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        xbee.getResponse().getZBRxResponse(rx);
        for (int i = 0; i < rx.getDataLength(); i++) {
          sample += (char)rx.getData(i);
        }
        Serial.println(sample);
      }
    }else if (xbee.getResponse().isError()) {
      Serial.println("Error reading packet.  Error code: ");  
      Serial.println(xbee.getResponse().getErrorCode());
  } 
  delay(1000);
}

This is working properly but now I want to increase the number of nodes so what should I supposed to do in that case. I want to find the acknowledgment of packet delivery and calculate the packet loss in a multi hop network.

Kindly give your kind suggestions.

Does zigbee have a 'ping' feature?
If not, program the destination node to send an ACK response back to the sending node. If an ACK isn't received then the message has been lost.

I have done that for two nodes i.e Sender and receiver, which works properly, but in more than two nodes I will broadcast a packet which acknowledgment does't work. I want to find packet loss in 4-5 nodes network. How can I do this?

Add code to the receiving Arduino that causes it to send a new message back to the sender every time it receives a message.