# Xbee Series 2 API mode communication

**URL:** https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740
**Category:** XBee - Zigbee
**Tags:** api, xbee, zigbee, communication, api-mode
**Created:** [October 14, 2014, 4:48am UTC](https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740 "2014-10-14T04:48:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![guti\_haz](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@guti\_haz](https://forums.digi.com/u/guti_haz)
#### Post date: [October 14, 2014, 4:48am UTC](https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740/1 "2014-10-14T04:48:33Z")

</div>

Hi,  
there are several topics out there regarding this kind of problem, but none of them are really solved to help me out here…

I simplified the example code of the Xbee library:  
\<\< in the second answer below you can find another try\>\>  
I first just want to send an Xbee package to my second Xbee (both connected to an Arduino Uno).  
Via onboard led pin 13 I want to show the state on my arduino boards.

I used the code from the “simple RX/TX” example and modified it:  
I send a package every 3500 ms…

```auto

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40b09937);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

void loop() {   
  payload[0] = 97;
  payload[1] = 98;

  xbee.send(zbTx);

  // flash TX indicator
  flashLed(statusLed, 1, 100);

  delay(3500);
}

```

and I just want to know if my second Xbee receives something, but LED 13 always blinks 3 times, meaning nothing arrives, am I right?  
Receiving Code:

```auto
void loop() {

  xbee.readPacket();

  if (xbee.getResponse().isAvailable()) {
    flashLed(statusLed, 1, 100);
  } 
  else if (xbee.getResponse().isError()) {
    flashLed(statusLed, 2, 100);
    //nss.print("Error reading packet. Error code: ");  
    //nss.println(xbee.getResponse().getErrorCode());
  } 
  else{
    flashLed(statusLed, 3, 100);
  }
  delay(1000);
}

```

In AT mode I have no problems sending data.  
I updated to the newest API firmware for one coordinator and one router - both have the same PanID…

I really don’t know how to troubleshoot this communication problems - any ideas?

---

<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: [October 30, 2014, 10:20am UTC](https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740/2 "2014-10-30T10:20:37Z")

</div>

What I would suggest is first take the module away from the processor and then connect them to a PC. Using XCTU, are you able to assemble a TX request packet and send it to the other module seeing it show up on the other module? Next once you have that working is to send the same packet you are sending with the arduinoi and see what it does. By going about it this way will help you to understand where the issue lies and where to go to address it.

---

<div class="post-metadata">

### Author: ![guti\_haz](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@guti\_haz](https://forums.digi.com/u/guti_haz)
#### Post date: [October 30, 2014, 3:51pm UTC](https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740/3 "2014-10-30T15:51:04Z")

</div>

Thanks for the tip,  
I already managed to send packets via XCTU and also by manual commands (sending byte by byte according to the ZigBee protocol): Both worked fine (data was received on remote Xbee and Response packet was received on local Xbee)  
Though I would like to test the Xbee library as it’s quite a deal of work writing these commands on my own… :-/  
Also I tried to just send the “request data” via the xbee.send(zbTx) command and read the incoming bytes via serial.read() (both on local and remote device) but nothing arrives.  
-\> I added another answer (below) - it shows my code on the Coordinator side

---

<div class="post-metadata">

### Author: ![guti\_haz](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@guti\_haz](https://forums.digi.com/u/guti_haz)
#### Post date: [October 30, 2014, 11:28pm UTC](https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740/4 "2014-10-30T23:28:52Z")

</div>

I simplified the code sample again - just sending the request “xbee.send(zbTx);”, then waiting for bytes to arrive on the the serial port (on both local & remote Xbee)  
-\> no data…

Below is the whole sketch on the local Arduino, I’m working with AltSoftSerial, so I can more or less debug via the Serial (USB) Port.  
On the remote Arduino I’m just reading the Serial Port for bytes to come in…

```auto

#include 
#include 

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

uint8_t payload[] = { 0x65, 0x66 };

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40b09937);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int statusLed = 13;
int errorLed = 13;

void flashLed(int pin, int times, int wait) {

  for (int i = 0; i &lt; times; i++) {
    digitalWrite(pin, HIGH);
    delay(wait);
    digitalWrite(pin, LOW);

    if (i + 1 &lt; times) {
      delay(wait);
    }
  }
}

void setup() {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);
  altSerial.begin(9600);
  Serial.begin(9600);
  xbee.setSerial(altSerial);
  Serial.println("Coordinator start");
}

void loop() {   
  
  delay(1500);
  xbee.send(zbTx);

  // flash TX indicator
  flashLed(statusLed, 1, 100);
  delay(500);
  
  while(altSerial.available() &gt; 0){
    Serial.println(altSerial.read());
  }
  delay(1000);
}

```

---

<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-series-2-api-mode-communication/13740/5 "2016-06-04T15:10:23Z")

</div>

Hi Guti,  
I’m going through a similar problem trying to get the Arduino to talk with the xBee S3B Digimesh in API mode.  
Printing though the serial the API massage is a bit tricky. You can use another Arduino to receive what goes out of the first Arduino… Please read below and let me know if this makes sense.  
!!!Nevertheless im not getting the right API msg !!!  
This is the code I use to in the Arduino “Sender” for sending data. In this particular case I’m trying to send a “Hi” but I think I’m getting the wrong API message in the output of the Arduino “7E01010107D33A2040B2FA4AFFFE00486955”  
I use another Arduino “Receiver” to check what is coming in the serial output of the Arduino Sender. In the real application this output would be connected to the xBee module.  
I think the API message that goes out of the Arduino sender should look like “7E 00 10 10 01 00 7D 33 A2 00 40 B2 FA 4A FF FE 00 00 48 69 55”

Do you see anything wrong in mi code?  
I’m using Andrew’s library “andrewrapp/xbee-arduino”

// Arduino Sender//////////////////////////////////////////////////////  
#include  
#include

// Create an XBee object at the top of your sketch  
XBee xbee = XBee();

int xBeeRX = 6; // Connect Arduino pin 8 to Xbee TX pin  
int xBeeTX = 7; // Connect Arduino pin 9 to Xbee RX pin  
SoftwareSerial xBeeSerial(xBeeRX, xBeeTX);// Define SoftwareSerial xBeeSerial RX/TX pins

// Create an array for holding the data you want to send.  
uint8\_t payload[] = {‘H’,‘i’}; //{48,69} in HEX

// Specify the address of the remote XBee (this is the SH + SL)  
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40B2FA4A);//0013A20040B2FA4A

// Create a TX Request  
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));

void setup() {  
xBeeSerial.begin(9600); // Start the serial port  
xbee.setSerial(xBeeSerial); // Tell XBee to use SoftwareSerial xBeeSerial  
}

void loop() {  
xbee.send(zbTx);// Send your request  
delay(10000);  
}

// Arduino Reciver//////////////////////////////////////////////////////  
//This Arduino is connected to the xBeeSerial of Arduino Sender. Just for debugging propose. #include

int xBeeRX = 6; // Connect Arduino pin 8 to Xbee TX pin  
int xBeeTX = 7; // Connect Arduino pin 9 to Xbee RX pin  
SoftwareSerial xBeeSerial(xBeeRX, xBeeTX);// Define SoftwareSerial xBeeSerial RX/TX pins

void setup() {  
// initialize both serial ports:  
Serial.begin(9600);  
xBeeSerial.begin(9600);  
}

void loop() {  
// read from port xBeeSerial, send to port Serial:  
if (xBeeSerial.available()) {  
int inByte = xBeeSerial.read();  
Serial.print(inByte, HEX);  
}  
}

---

<div class="post-metadata">

### Author: ![guti\_haz](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@guti\_haz](https://forums.digi.com/u/guti_haz)
#### Post date: [June 6, 2016, 12:30pm UTC](https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740/6 "2016-06-06T12:30:24Z")

</div>

Hi,

well, it has been a while and i’m not into it right now (i am in kyrgyzstan atm 😉 )  
Don’t see the mistake, but I couldn’t make it run with the xbee objects from the library so i send the message manually according to the xbee protocol… (startbyte, 2 length bytes,…)  
I can send you some information papers, if you give me your email.

It’s a bit difficult for me also now as my phone is struggling with opening some files, so i can’t check everything…

---

<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 6, 2016, 11:15pm UTC](https://forums.digi.com/t/xbee-series-2-api-mode-communication/13740/7 "2016-06-06T23:15:17Z")

</div>

Hi Guti,  
Thanks for getting back to me. Any information you can send will be appreciated. [jortronm@hotmail.com](mailto:jortronm@hotmail.com)
