I am using xbee pro series 1 in Api mode for communication. One Co-ordinator and two end devices. I am able to send data from to Co-ordinator to end device but when I am trying to send and receive simultaneously from end device there is an error. How should I do this?(I used Andrew rapp xbee library).
CO- ORDINATOR CODE:
#include <Xbee.h>
XBee xbee = XBee();
uint8_t payload[] = { 12, 15 };
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40AACFA1);
Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload));
XBeeResponse response = XBeeResponse();Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();
void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
}
void loop() {
xbee.send(tx);
delay(1000);
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
// got something
Serial.println("hurraah");
if (xbee.getResponse().getApiId() == RX_16_RESPONSE || xbee.getResponse().getApiId() == RX_64_RESPONSE) {
Serial.println("got a rx packet");
if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
xbee.getResponse().getRx16Response(rx16);
uint8_t data[15];
for (int i = 0; i < rx16.getDataLength(); i++) {
data[i] += rx16.getData(i);
}
Serial.println(data[0]);
Serial.println(data[1]);
data[0] = 0;
data[1] = 0;
} else {
xbee.getResponse().getRx64Response(rx64);
Serial.println("it's 64! ");
}
} else {
Serial.println("didnot receive packet");
}
} else if (xbee.getResponse().isError()) {
Serial.println("error");
}
delay(1000);
}
END DEVICE CODE:
#include <Xbee.h>
XBee xbee = XBee();
uint8_t payload[] = {27, 49};
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40AACFB4);
Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload));
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();
uint8_t data[15];
void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
}
continuously reads packets, looking for RX16 or RX64
void loop() {
xbee.send(tx);
delay(1000);
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
// got something
Serial.println("hurraah");
if (xbee.getResponse().getApiId() == RX_16_RESPONSE || xbee.getResponse().getApiId() == RX_64_RESPONSE) {
Serial.println("got a rx packet");
if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
xbee.getResponse().getRx16Response(rx16);
for (int i = 0; i < rx16.getDataLength(); i++) {
data[i] += rx16.getData(i);
}
Serial.println(data[0]);
Serial.println(data[1]);
data[0] = 0;
data[1] = 0;
} else {
xbee.getResponse().getRx64Response(rx64);
Serial.println("it's 64! ");
}
} else {
Serial.println("something unexpecting");
}
} else if (xbee.getResponse().isError()) {
Serial.println("error");
}
delay(1000);
}
Thank you,
Lucy.