I am trying to establish XBee communication using API mode. I wanted to get the data received by XBee using Interrupts. I am using the below code but i could not read data. can any one suggest some way of reading data received by XBee using Interrupts
#include
#include
#include
#include
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
SoftwareSerial test(2,1);
String sample;
void setup() {
Serial.begin(9600);
xbee.begin(test);
attachInterrupt(0, receiveData, CHANGE );
}
void receiveData() {
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
xbee.getResponse().getZBRxResponse(rx);
for (int i = 0; i < rx.getDataLength(); i++) {
sample += (char)rx.getData(i);
}
}
}else if (xbee.getResponse().isError()) {
sample += xbee.getResponse().getErrorCode();
}
}
void loop() {
Serial.println(sample);
delay(1000);
}