Serial Communication between XBee using Arduino

Hi Robin, I've resolved all the previous problems and now the data was transmitting the way I wanted. There was a change in the requirement of the project as earlier I was sending a broadcasted message, now I need to send as a unicast message. Means that now we have to take value from the user to send the message to the desired router. This thing should be done autonomously which I shall be seeing when an actual sensor is attached instead of generating a random number.

I used a help from your topic on "Serial Input Basics - updated" which helped me in taking input from the serial monitor and I must say it was a great help.

Now, the problem I'm facing is that at the time of taking input in the XBee mode of the Sainsmart Arduino-XBee Shield which is used to communicate between XBee and Arduino. Whatever, input I'm taking is not getting displayed on the serial monitor. So, my question is, do we have to apply a similar code at the receiving end just like we did at the transmitting end or that code works fine and I'm doing mistake at somewhere else.

I'm attaching my code for your reference.

#include <XBee.h>
#include <time.h>
#include <stdlib.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
XBeeAddress64 ROUTER1 = XBeeAddress64(0x0013A200,0x4147FE2A);
XBeeAddress64 ROUTER2 = XBeeAddress64(0x0013A200,0x4147FE2B);
XBeeAddress64 ROUTER3 = XBeeAddress64(0x0013A200,0x4147FE2E);
XBeeAddress64 ROUTER4 = XBeeAddress64(0x0013A200,0x414E65AA);
XBeeAddress64 ROUTER5 = XBeeAddress64(0x0013A200,0x414E65AE);
XBeeAddress64 ROUTER6 = XBeeAddress64(0x0013A200,0x414E65B1);
uint8_t count = 0;
uint8_t input = 0;
String sample = "";
void setup() 
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  srand((unsigned)time(NULL));
}

void loop() 
{
  delay(1000);
  transmitXBee();
  delay(1000);
  receiveXBee();
  delay(1000);
}

void transmitXBee()
{
  uint8_t i = 0;
  uint8_t data[3];
  uint8_t receivedChar = '0';
  boolean newData = false;
  data[0] = '6';
  data[1] = rand()%256;
  data[2] = ',';
  data[3] = rand()%256;
  ZBTxRequest zbTx1 = ZBTxRequest(ROUTER1, data, sizeof(data));
  ZBTxRequest zbTx2 = ZBTxRequest(ROUTER2, data, sizeof(data));
  ZBTxRequest zbTx3 = ZBTxRequest(ROUTER3, data, sizeof(data));
  ZBTxRequest zbTx4 = ZBTxRequest(ROUTER4, data, sizeof(data));
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, data, sizeof(data));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, data, sizeof(data));
  
  delay(500);
  Serial.println("Start Transmitting");
  Serial.print("Data Sent:\t");
  Serial.print(data[0]);
  Serial.print(data[1]);
  Serial.print(data[2]);
  Serial.println(data[3]); 
  delay(500);
  if (Serial.available() > 0) 
  {
    receivedChar = Serial.read();
    newData = true;
  }
  if (newData == true) 
  {
    Serial.print("Input: ");
    Serial.println(receivedChar);
    newData = false;
    switch(receivedChar)
    {
      case '1':
        Serial.println("To Router 1");
        xbee.send(zbTx1);
        Serial.println();
        delay(500);
        break;
      case '2': 
        Serial.println("To Router 2");
        xbee.send(zbTx2);
        Serial.println();
        delay(500);
        break;
      case '3': 
        Serial.println("To Router 3");
        xbee.send(zbTx3);
        Serial.println();
        delay(500);
        break;
      case '4': 
        Serial.println("To Router 4");
        xbee.send(zbTx4);
        Serial.println();
        delay(500);
        break;
      case '5':
        Serial.println("To Router 5");
        xbee.send(zbTx5);
        Serial.println();
        delay(500);
        break;
      default: 
        Serial.println("Wrong input entered");
        break;
    }
  }
}

void receiveXBee()
{
  xbee.readPacket(500);
  Serial.println("Reading for Packet");
  if(xbee.getResponse().isAvailable())
  {
    Serial.print("Packet Available: ");
    Serial.println(count);
    delay(500);
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      xbee.getResponse().getZBRxResponse(rx);
      delay(300);
      
      for(int i=0; i<rx.getDataLength(); i++)
      {
        sample += (char)rx.getData(i);
        //Serial.print(rx.getData(i),DEC);
      }
      Serial.print("count: ");
      count++;
      Serial.println(count);
      Serial.print("Packet Received: ");
      Serial.println(sample);
      delay(1500);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
    delay(500);
  } 
}