Serial Communication between XBee using Arduino

As you see in the following code, I've passed "HI, I'M Router 5!" in the data field, which is an unsigned character array.

#include <XBee.h>
#include <stdlib.h>
#include <string.h>
XBee xbee = XBee();
XBee xbee1 = 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); 
String sample;
uint8_t count = 0;
void setup() 
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  Serial.println("Start Transmitting");
}

void loop() 
{
  uint8_t i = 0;
  uint8_t data[] = "HI, I'M Router 5!";
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, data, sizeof(data));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, data, sizeof(data));
  sample = "";
  while(i<1)
  {
    xbee.send(zbTx6);
    Serial.println("To Router 6");
    delay(1000);
    i++;
  }

  //Convert a string into uint8_t
  //String myString = "By Priyanshu";
  //data = atoi(myString.c_str());
  //char buf[myString.length()+1];
  //myString.toCharArray(buf, myString.length()+1);
  //data = ((uint8_t*)buf, strlen(buf));

  xbee.readPacket(500);
  Serial.println("Packet Detected");
  Serial.print("count: ");
  Serial.println(count);
  if(xbee.getResponse().isAvailable())
  {
    Serial.println("Packet Arrived");
    Serial.print("count: ");
    Serial.println(count);
    //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.print("From Router 5: ");
      Serial.println(sample);
      count++;
      Serial.print("count: ");
      Serial.println(count);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
  }
  delay(1000); 
}

I need help exactly at this point:

  //Convert a string into uint8_t
  //String myString = "By Priyanshu";
  //data = atoi(myString.c_str());
  //char buf[myString.length()+1];
  //myString.toCharArray(buf, myString.length()+1);
  //data = ((uint8_t*)buf, strlen(buf));

The error I was getting when I uncommented this above piece of code is:

incompatible types in assignment of 'size_t {aka unsigned int}' to 'uint8_t [18] {aka unsigned char [18]}'

Now, my question is I've to update my location at every point where on the color map where I'll be getting the sensor value in x and y coordinates.

Now, suppose if you replace the message "HI, I'M Router 5!" to some integer but it should be a character array. And, the new data which will be getting after getting values from the sensor needs to be updated in the data[] also known as payload[] which is transmitted from one XBee to another.

For example: At present, the Robot is present at (24, 50) coordinates :
uint8_t data[] = "24, 50"; ---------> //The coordinate axis at which the LEGO Robot is standing
now when the loop initiates again or Robot moves from its place,
the new coordinates are 36, 80 at which the LEGO Robot is present.
So I want my data to be updated to:
uint8_t data[] = "36, 80"; ---------> //New value of the LEGO Robot.
Similarly, every time the loop initiates the LEGO Robot should update its location and transmit it to the other LEGO Robots.

I hope I'm clear this time. Sorry, since not having much experience so, don't know how to ask exactly on the forum.

Priyanshu27:
I hope I'm clear this time.

Sorry, No. You seem to be making heavy weather of my simple question.

You start with data[] = "HI, I'M Router 5!";

All I want to know is what the HI, I'M Router 5! should be changed to?

For example, should it change to "Elephants" or to "GoodBye" or to "123 cats" or what?

(and thanks for posting the code in code tags).

...R

You start with data[] = "HI, I'M Router 5!";

For instance, I started with the data containing a location of let say some coordinates instead of "HI, I'M Router 5!" and now I want to update its location next time loop initiates.

All I want to know is what the HI, I'M Router 5! should be changed to?

For example, should it change to "Elephants" or to "GoodBye" or to "123 cats" or what?

Yeah, you can say if next time loop initiates, we change it to "Elephant". Then again next time it changes to "123 cats", and after that "Ice-cream". However, they are so random changes which I know not possible to be done, but can we update the data already stored into something different, next time the loop initiates. This is my question.

Priyanshu27:
Yeah, you can say if next time loop initiates, we change it to "Elephant". Then again next time it changes to "123 cats", and after that "Ice-cream". However, they are so random changes which I know not possible to be done, but can we update the data already stored into something different, next time the loop initiates. This is my question.

I suspect you don't really want to change it to "Elephant" or Ice-cream" and I am beginning to think that there is some specific reason why you are not prepared to say what you do want to change it to. Perhaps it is for an illegal or anti-social purpose and if so I don't intend to help.

This is the last time of asking - give some actual examples of what you want to put into the array in place of HI, I'M Router 5!

...R

I suspect you don't really want to change it to "Elephant" or Ice-cream" and I am beginning to think that there is some specific reason why you are not prepared to say what you do want to change it to. Perhaps it is for an illegal or anti-social purpose and if so I don't intend to help.

Yeah, I don't want to change data to "Elephant or Ice-cream". As I just want a location in terms of coordinates to get updated. I tell you my actual project. There are 6 LEGO EV3 Mindstorm Robots on which Arduino UNO is mounted. Now, there is color sensor used on a pixel map made from either two colors of the RGB colors so that we can use every pixel as a coordinate. Also, there is an ultrasonic sensor to detect the presence of other sensor and by calculating the distance between two robots, we use Smooth Turn Mobility model for collision avoidance and path navigation. XBees are used to transfer the data wirelessly.

This is the last time of asking - give some actual examples of what you want to put into the array in place of HI, I'M Router 5!

For once, please don't misunderstand that I want to send the data as "HI, I'M Router 5!". I gave it in the code for understanding that at exactly which place we want to transfer. In the actual project, I shall be reading the sensor data of a gyro sensor or an ultrasonic sensor and get the coordinates.

For example, as I mentioned of sending coordinates in data[] = "37, 19". Next time loop initiates, the robot position changed to (57,78) so I want data to be updated as data[] = "57, 78".

Priyanshu27:
For example, as I mentioned of sending coordinates in data[] = "37, 19". Next time loop initiates, the robot position changed to (57,78) so I want data to be updated as data[] = "57, 78".

Hooray --- Finally ---

And, as I suspected when I asked back in Reply #1, there is a much easier way to send the data you actually want to send

Try something like this (I don't have an Xbee so I may have not got the syntax perfectly correct

xVal = 37;
yVal = 19;
myXbee.print(xVal);
myXbee.print(','); // comma
myXbee.print(yVal);

...R

Try something like this

By this way we can't print values, however, I find out a solution to it that I can generate random values between 1 and 100 to get a coordinates value. But, the place I got stuck with this is there are 6 XBee connected to each other and all are sending data to each other. Then how do we get to know that from which XBee we are getting our values?

#include <stdio.h>
#include <time.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Initializing the program");
  srand((unsigned)time(NULL));
}

void loop() {
  // put your main code here, to run repeatedly:
  uint8_t i = 0;
  //srand((unsigned)time(NULL));
  while(i<5)
  {
    uint8_t x = rand()%100;
    uint8_t y = rand()%100;
    uint8_t xy[] = {x,y};
    Serial.print(xy[0],xy[1]);
    Serial.println();
    i++;
  }
}

Can you suggest some way for it.

Priyanshu27:
By this way we can't print values

I don't understand that - what can you do? I have not used XBees myself. Do you mean that xbee.print() is not valid? If so, what is the correct syntax? My general understanding is that XBees just send serial data - but maybe I am wrong.

On the other hand maybe you can put your values into an array of ints and send that?

Can you post a link to the documentation for the Xbee library that you are using?

But, the place I got stuck with this is there are 6 XBee connected to each other and all are sending data to each other. Then how do we get to know that from which XBee we are getting our values?

Include in each message an ID number for the sender.

...R

Can you post a link to the documentation for the Xbee library that you are using?

Link for the documentation:

GitHub - andrewrapp/xbee-arduino: Arduino library for communicating with XBee radios in API mode

Do you mean that xbee.print() is not valid?

Yes, because there is no print function defined in xbee library.

nclude in each message an ID number for the sender

Can you provide an example of it because I was not able to understand it?
I tried passing a message along with the random values to which I got an error message.

no matching function for call to 'HardwareSerial::print(uint8_t&, uint8_t&, uint8_t&)'

Thanks for the link. It's very irritating that there is no online documentation so I had to download the library. And the documentation is crap - it does not explain "send" at all. But there are some examples and it seems I have been barking up the wrong tree (not for the first time).

If you want to send (say) three numbers then create an array, make an XBee object with it, put the values you want into the array, and send the array. Like this, I think

int myArray[3];
ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, myArray, sizeof(myArray));
myArray[0] = thisXBeeID; //   I assume you will give each one a different number
myArray[1] = xVal;
myArray[2] = yVal;
xbee.send(zbTx5);

...R

PS ... where did you get the idea for such cryptic names for your variables :slight_smile:

But there are some examples and it seems I have been barking up the wrong tree (not for the first time).

Sorry Man, I'm not an expert at coding. But, I'm trying to ask in the easiest manner I can.

If you want to send (say) three numbers then create an array, make an XBee object with it, put the values you want into the array, and send the array.

I tried it earlier when I got an error.

uint8_t xy[3];
xy[0] = "XBeeId 1:";
xy[1]= rand()%100;
xy[2] = rand()%100;
Serial.print(xy[0],xy[1],xy[2]);
//Serial.print(xy[0]);
//Serial.print(",");
//Serial.print(xy[1]);
//Serial.println(xy[2]);
ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, xy, sizeof(xy));
xbee.send(zbTx5);

Error Message:

no matching function for call to 'HardwareSerial::print(uint8_t&, uint8_t&, uint8_t&)'

The output I want in return should be like in this format:
XBeeId 1: 28,34

And same way I want to get at the receiver side.

Is it possible to print? Sorry for asking such silly questions.

Priyanshu27:
Error Message:

no matching function for call to 'HardwareSerial::print(uint8_t&, uint8_t&, uint8_t&)'

You need to post the complete program so we can see how all the variables are defined.

The output I want in return should be like in this format:
XBeeId 1: 28,34

And same way I want to get at the receiver side.

I don't believe there is any need for the style XBeeId 1: 28,34. All that needs to be sent is 3 numbers in an array with no colons or commas or text. The receiving program will be written to expect that and everything will be much simpler.

...R

You need to post the complete program so we can see how all the variables are defined.

#include <XBee.h>
#include <stdlib.h>
#include <time.h>
XBee xbee = XBee();
XBee xbee1 = 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 sample;
uint8_t count = 0;
void setup() 
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  Serial.println("Start Transmitting");
  srand((unsigned)time(NULL));
}

void loop() 
{
  uint8_t i = 0;
  uint8_t xy[3];
  //Serial.print("Data Sent: ");
  xy[0] = "XBeeId:";
  xy[1] = rand()%10;
  xy[2] = rand()%10;
  Serial.print(xy[0]);
  Serial.print(xy[1]);
  Serial.print(",");
  Serial.println(xy[2]);
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, xy, sizeof(xy));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, xy, sizeof(xy));
  //sample = "";
  while(i<1)
  {
    xbee.send(zbTx5);
    Serial.println("... To Router 5 ...");
    delay(1000);
    i++;
  }
  xbee.readPacket(500);
  Serial.println("Packet Detected");
  Serial.print("count: ");
  Serial.println(count);
  if(xbee.getResponse().isAvailable())
  {
    Serial.println("Packet Arrived");
    Serial.print("count: ");
    Serial.println(count);
    //Serial.println(xbee.getResponse().getApiId());
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      xbee.getResponse().getZBRxResponse(rx);
      Serial.print("Data Received: ");
      for(int i=0; i<rx.getDataLength(); i++)
      {
        //sample+= (char)rx.getData(i);
        Serial.print(rx.getData(i),DEC);
      }
      //Serial.println(sample);
      count++;
      Serial.print("count: ");
      Serial.println(count);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
  }
  delay(1000); 
}

I don't believe there is any need for the style XBeeId 1: 28,34

Yeah, we don't need to style like this but by just sending three numbers there may be a possibility of reading wrong coordinates.

For example, suppose we sending data from Router 1 to Router 5 with a location of (2,34). So, the data received at Router 5 will be 1234. Here, we can say 1 stands for Router 1 but for the coordinates, we may read as (23,4) or (2,34). So we can read an incorrect location as well. How to get rid of that?

Assuming the code in Reply #20 is what gave rise to the error message in Reply #18, I can't figure out what the problem might be without knowing the line number reported along with the error message. Post the complete error message.

For example, suppose we sending data from Router 1 to Router 5 with a location of (2,34). So, the data received at Router 5 will be 1234.

There will be no ambiguity. On the receiving side there will also be an array with 3 elements. receivedData[0] will have the ID number; receivedData[1] will have the xValue and receivedData[2] will have the yValue. (Obviously you can choose your own array name)

...R

Post the complete error message.

This was the complete error message:

error: no matching function for call to 'HardwareSerial::print(uint8_t&, uint8_t&, uint8_t&)'
** Serial.print(xy[0],xy[1],xy[2]);**

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

On the receiving side there will also be an array with 3 elements

As you see in the code, we are getting the received data by using (rx.getData(i), DEC). I guess, but not sure if it is getting data bit by bit or it taking data as a packet. So, can you suggest a way of getting a data packet in form of an array with three elements?

Priyanshu27:
This was the complete error message:

error: no matching function for call to 'HardwareSerial::print(uint8_t&, uint8_t&, uint8_t&)'
** Serial.print(xy[0],xy[1],xy[2]);**

Somehow I think there is more. Never mind the fancy orange colour - just copy and paste the error message from the Arduino IDE.

As you see in the code,

I can't see because you have not posted the complete program.

And I presume you have realized that if you change the way you send data you also have to change the way it is received so that the receiving code matches the sending code.

Post the latest versions of your sending and receiving programs. There is no value looking at only one of them. That's like one-handed clapping.

...R

just copy and paste the error message from the Arduino IDE.

That was the entire error I was getting. I've copied and pasted it as it is. Just highlighted it with a fancy orange color so that you can see it.

I can't see because you have not posted the complete program.

If you see Reply #20, I've posted my complete updated code. However, in Reply #22 I posted on receiver code again because I wanted to ask problem from that part of the code.

And I presume you have realized that if you change the way you send data you also have to change the way it is received so that the receiving code matches the sending code

If you see my entire code, as said by you to assign an ID no. to every router so that we can know from which router data is coming. But the issue I was facing on the receiver side is that we are getting data bit by bit and I'm not able to collect the data coming from the respective array into different arrays. If you can see the code and tell me how to create arrays at the receiving end and how to store the incoming data into it, it will be a huge huge help.

I'm attaching my complete code again just in case you face problem in going back and forth for different replies.

#include <XBee.h>
#include <stdlib.h>
#include <time.h>
XBee xbee = XBee();
XBee xbee1 = 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 sample;
uint8_t count = 0;
void setup() 
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  Serial.println("Start Transmitting");
  srand((unsigned)time(NULL));
}

void loop() 
{
  uint8_t i = 0;
  uint8_t xy[3];
  //Serial.print("Data Sent: ");
  xy[0] = "XBeeId:";
  xy[1] = rand()%10;
  xy[2] = rand()%10;
  Serial.print(xy[0]);
  Serial.print(xy[1]);
  Serial.print(",");
  Serial.println(xy[2]);
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, xy, sizeof(xy));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, xy, sizeof(xy));
  //sample = "";
  while(i<1)
  {
    xbee.send(zbTx5);
    Serial.println("... To Router 5 ...");
    delay(1000);
    i++;
  }
  xbee.readPacket(500);
  Serial.println("Packet Detected");
  Serial.print("count: ");
  Serial.println(count);
  if(xbee.getResponse().isAvailable())
  {
    Serial.println("Packet Arrived");
    Serial.print("count: ");
    Serial.println(count);
    //Serial.println(xbee.getResponse().getApiId());
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      xbee.getResponse().getZBRxResponse(rx);
      Serial.print("Data Received: ");
      for(int i=0; i<rx.getDataLength(); i++)
      {
        //sample+= (char)rx.getData(i);
        Serial.print(rx.getData(i),DEC);
      }
      //Serial.println(sample);
      count++;
      Serial.print("count: ");
      Serial.println(count);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
  }
  delay(1000); 
}

The data which we are taking at the receiver end is in this manner:

 if(xbee.getResponse().isAvailable())
  {
    Serial.println("Packet Arrived");
    Serial.print("count: ");
    Serial.println(count);
    //Serial.println(xbee.getResponse().getApiId());
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      xbee.getResponse().getZBRxResponse(rx);
      Serial.print("Data Received: ");
     for(int i=0; i<rx.getDataLength(); i++)          //This the loop for taking the receiving values.
      {
        //sample+= (char)rx.getData(i);
        Serial.print(rx.getData(i),DEC);              //Here, we are printing the received value
      }
      //Serial.println(sample);
      count++;
      Serial.print("count: ");
      Serial.println(count);
    }
  }

Priyanshu27:
I'm attaching my complete code again just in case you face problem in going back and forth for different replies.

Thank you for that.

However you seem to have posted the complete transmitting program but only part of the receiving program. Please post two complete programs.

And I remain sceptical about the completeness of your error message. I deliberately caused an error in a simple program and this is the message I got

ArduinoTemp.ino: In function 'void loop()':
ArduinoTemp.ino:22:20: error: 'low' was not declared in this scope
Error compiling.

You can see that it has identified the name of the program, the function where the error was and the line and character number where it was detected.

...R

However you seem to have posted the complete transmitting program but only part of the receiving program. Please post two complete programs.

There are no two codes as I'm using this code as the complete code. However, you may be finding the receiver code incomplete because I might have written an incomplete code for receiving the data. As my coding is not strong, I'm seeking help from the forum if I can get the completeness in my code.

And I remain skeptical about the completeness of your error message

#include <XBee.h>
#include <stdlib.h>
#include <time.h>
XBee xbee = XBee();
XBee xbee1 = 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); 
String sample;
uint8_t count = 0;
void setup() 
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  Serial.println("Stating Up!");
  Serial.println("Start Transmitting");
  srand((unsigned)time(NULL));
}

void loop() 
{
  uint8_t i = 0;
  uint8_t x = rand()%10;
  uint8_t y = rand()%10;
  uint8_t c = "XBeeId 1:";
  uint8_t data[] = {x,y};
  Serial.print(c,data[0],data[1]);
  //uint8_t data[] = "HI, I'M Router 5!";
  ZBTxRequest zbTx5 = ZBTxRequest(ROUTER5, data, sizeof(data));
  ZBTxRequest zbTx6 = ZBTxRequest(ROUTER6, data, sizeof(data));
  sample = "";
  while(i<1)
  {
    xbee.send(zbTx6);
    Serial.println("To Router 6");
    delay(1000);
    i++;
  }
  //String myString = "By Priyanshu";
  //data = atoi(myString.c_str());
  //char buf[myString.length()+1];
  //myString.toCharArray(buf, myString.length()+1);
  //data = ((uint8_t*)buf, strlen(buf));
  xbee.readPacket(500);
  Serial.println("Packet Detected");
  Serial.print("count: ");
  Serial.println(count);
  if(xbee.getResponse().isAvailable())
  {
    Serial.println("Packet Arrived");
    Serial.print("count: ");
    Serial.println(count);
    //Serial.println(xbee.getResponse().getApiId());
    if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
    {
      Serial.print("From Router 6: ");
      xbee.getResponse().getZBRxResponse(rx);
      for(int i=0; i<rx.getDataLength(); i++)
      {
        //sample+= (char)rx.getData(i);
        Serial.println(rx.getData(i),DEC);
      }
      count++;
      Serial.print("count: ");
      Serial.println(count);
    }
  }
  else if(xbee.getResponse().isError())
  {
    Serial.print("Error Reading Packet. Error Code: ");
    Serial.println(xbee.getResponse().getErrorCode());
  }
  delay(1000); 
}

Try this code as I run on my machine and I'm getting this error. However, my objective from this error message is that at the transmitting end I'm able to send an ID no. but cannot differentiate that the coordinates I'm sending, how to figure it out.

As the random values, I'm generating as of now is between 0 to 9 just for the understanding purpose. But, in future, I shall be sending between 0 to 255 as there are in total 256 pixels of any color. So at that time how do we segregate the coordinates. Like the example, I gave earlier we are sending ID no. (say) 5 so we know it's ASCII value is 53 and the coordinates are (12,206). The output I'm getting is 5312206. So, how do we know if it is (12,206) or (122,06)? That's the problem I'm facing.

I know I've made it a big hype out of it, but as I mentioned my coding is not strong and this is an entirely new project for me so I'm facing a lot of challenges with it. You people being expert and thoroughly active on the forum to help the rookie coders might help me with it.

Priyanshu27:
There are no two codes as I'm using this code as the complete code.

You will make life a great deal easier for yourself if you create two separate programs - one for transmit and one for receive. At least do that until you are know how to get the communication working. Just make the simplest programs possible that will send and receive the data in the format you require.

It will also make it a great deal easier to help you.

When you have it working then you can combine the code into a single program if you wish.

...R