I have been trying to make two xbees communicate for a long time. I have checked everything and at last i come here for some help from the experts or who have already stumbled upon the same problem as mine. I am using series 2 xbees.
I am using this library
Its a pretty basic circuit.
The coordinator has a buttion. And the router has led. When i press button on coordinator, i send two bytes as payload to the router. The router checks if packet was received if yes, it checks if the correct byte is received. If yes, it turns on the led. I am not able to turn on the led no matter what i do. I appreciate your help.
The code for coordinator(sender):
#include <XBee.h>
// create the XBee object
XBee xbee = XBee();
uint8_t payload[] = { 0, 0 };
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x408698be);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
int pin5 = 0;
void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
}
void loop() {
payload[0] = 0x34;
payload[1] = 0x76;
if (digitalRead(7) == HIGH){
xbee.send(zbTx);
delay(1000);
}
}
And the code for router(receiver) is:
#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
void setup() {
// start serial
Serial.begin(9600);
xbee.begin(Serial);
}
// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
// got something
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
// got a zb rx packet
// now fill our zb rx class
xbee.getResponse().getZBRxResponse(rx);
//i check both bytes (or)
if(rx.getData(0) == 0x34 || rx.getData(0) == 0x76 ){
digitalWrite(8, HIGH);
}
}
}
}
Thank you!