# Xbee in API mode for digimesh

**URL:** https://forums.digi.com/t/xbee-in-api-mode-for-digimesh/16103
**Category:** XBee - DigiMesh
**Tags:** xbee, api-mode, arduino
**Created:** [January 18, 2016, 8:20am UTC](https://forums.digi.com/t/xbee-in-api-mode-for-digimesh/16103 "2016-01-18T08:20:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pejamar](https://avatars.discourse-cdn.com/v4/letter/p/d9b06d/32.png) [@pejamar](https://forums.digi.com/u/pejamar)
#### Post date: [January 18, 2016, 8:20am UTC](https://forums.digi.com/t/xbee-in-api-mode-for-digimesh/16103/1 "2016-01-18T08:20:25Z")

</div>

I want to connect some arduinos mega with Xbee DigiMesh 2.4 in a mesh network.

At this moment i try to connect 2 of them, one sender and one receiver, thats the code that i have on them:

Sender:

#include

// create the XBee object  
XBee xbee = XBee();

uint8\_t payload[] = { 0, 0 };

// SH + SL Address of receiving XBee  
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40E73B5E);  
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;

delay(3000);  
xbee.send(zbTx);

}

Receiver

#include

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);  
Serial1.begin(9600);  
xbee.begin(Serial1);  
}

// continuously reads packets, looking for ZB Receive or Modem Status  
void loop() {  
xbee.readPacket();  
if (xbee.getResponse().isAvailable()) {  
// got something  
Serial.println(“got something”);  
if (xbee.getResponse().getApiId() == ZB\_RX\_RESPONSE) {  
// got a zb rx packet  
Serial.println(“got 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);  
}  
}  
}

With this code i connect Serial1 to the Xbee. And i have on the hardware selected API(1) mode.

I dont know the reason why i can`t comunicate, if i need to use other libraries or what.

Thanks.

---

<div class="post-metadata">

### Author: ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)
#### Post date: [January 18, 2016, 3:33pm UTC](https://forums.digi.com/t/xbee-in-api-mode-for-digimesh/16103/2 "2016-01-18T15:33:39Z")

</div>

I don’t know what lib you are using as there are several out there but I would suggest using API mode 2 as most of them use this mode and I would also suggest a book called Creating Sensors Networks by Rob Faluti.

---

<div class="post-metadata">

### Author: ![jortronm](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jortronm](https://forums.digi.com/u/jortronm)
#### Post date: [June 4, 2016, 3:10pm UTC](https://forums.digi.com/t/xbee-in-api-mode-for-digimesh/16103/3 "2016-06-04T15:10:37Z")

</div>

Hi PejaMar, Have you got your application working? If yes, would you please share the Arduino code. Thanks
