XBee with Photon P0

Hey guys,
I need your help. I’m trying to hook a XBee radio to Particle. I have a working code from arduino and am connecting it as i will connect it on my arduino. I’m configuring the particle XBee as router in API mode 2. i’m sending a packet from XBee coordinator which shows a successful delivery. but at the RX side i get false on checking if the XBee radio received any packet. All the XBee are on same pan id and same firmware. I’m attaching the code also for reference. The coordinator is generating frame from XCTU software. dependencies.XBee=0.0.10 - >Xbee library i’m using for photon

Code RX:

#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
void setup() {
  Serial.begin(9600);
  xbee.begin(Serial);
}
void loop() {
String sample;
  xbee.readPacket(); 
    if (xbee.getResponse().isAvailable()) {  // -> statement returning false
      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.println(sample);
      }
    }else if (xbee.getResponse().isError()) {
      Serial.println("Error reading packet.  Error code: ");  
      Serial.println(xbee.getResponse().getErrorCode());
  } 
  delay(100);
}

You want to use Serial1 - Serial refers to the USB Serial interface.

2 Likes

Thank you. It worked.

1 Like

Ive been playing with XBee over here also: Photon + XBee Digi MESH

@RWB is there any way I can share the pan id of the network dynamically? Like the router adds itself to the network? Something in that direction.

I would look at the 3 example programs in this library where in one of them they set the Pan ID of the Radio using the Microcontroller.