Home/Support/Support Forum/Xbee Series 2 API mode communication

Xbee Series 2 API mode communication

0 votes
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...
Code:
// 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:
Code:
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?
asked Oct 14, 2014 in ZigBee PRO Featureset (and legacy ZNet 2.5) by guti_haz New to the Community (2 points)
edited Oct 31, 2014 by guti_haz

Please log in or register to answer this question.

2 Answers

0 votes
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.
answered Oct 30, 2014 by mvut Veteran of the Digi Community (15,223 points)
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
0 votes
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...
Code:
#include <AltSoftSerial.h> #include <XBee.h> 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 < times; i++) { digitalWrite(pin, HIGH); delay(wait); digitalWrite(pin, LOW); if (i + 1 < 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() > 0){ Serial.println(altSerial.read()); } delay(1000); }
answered Oct 30, 2014 by guti_haz New to the Community (2 points)
edited Oct 31, 2014 by guti_haz
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 <XBee.h>
#include <SoftwareSerial.h>

// 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 <SoftwareSerial.h>

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);
  }
}
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...
Hi Guti,
Thanks for getting back to me. Any information you can send will be appreciated. jortronm@hotmail.com
...