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.