PC Coordinator + XBee Arduino + API mode

Hello every body :slight_smile:

I need your help about this !
I have a 3 XBee modules and I want to connect the coordinator to PC and the 2 routers to Arduino so I have tried many codes to get communication and nothing worked even I tried to connect coordinator to arduino and tried to communicate with router on arduino and nothing worked...

I have configured the XBee modules with the latest firmware and DH=0, DL=ffff, AP=2 for coordinator and DH=0, DL=0, AP=2 for routers

the code that I had tried is from the following thread
http://arduino.cc/forum/index.php/topic,90128.0.html

The transmitter code :
Code:

#include <XBee.h>

uint8_t text[] = {'H', 'e', 'l', 'l', 'o'};

XBee xbee = XBee();
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013a200, 0x407a3903);
ZBTxRequest zbTx = ZBTxRequest(remoteAddress, text, sizeof(text));

void setup () {
delay(1000);
xbee.begin(9600);
}

void loop () {
xbee.send(zbTx);
delay(3000);
}

The receiver code :
Code:

#include <XBee.h>

XBee xbee = XBee();
ZBRxResponse zbRx = ZBRxResponse();

void setup () {
delay(1000);
xbee.begin(9600);
Serial.println("starting up yo!");
}

void loop () {

// 1. This will read any data that is available:
xbee.readPacket();

// 2. Now, to check if a packet was received:
if (xbee.getResponse().isAvailable()) {
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
xbee.getResponse().getZBRxResponse(zbRx);

for (int i = 0; i < zbRx.getDataLength(); i++) {
Serial.print("payload [");
Serial.print(i, DEC);
Serial.print("] is ");
Serial.print(zbRx.getData(i));
}
}
}
}

I need to make a simple communication in API mode but nothing work and tested code could help me I will appreciated and I appreciate any help :slight_smile:
Regards :slight_smile:

Hello Fouad,

Have you downloaded the Xbee library to your Arduino software?

Did you changed the address of the remote device in the transmitter code?

first of all mismas_nc many many thanks for your reply :slight_smile:
yes I have done this correctly, I've tried to send the API frame using X-CTU just XBee to XBee on the explorers and they work good
but I want to use arduino with XBee, the problem is the code dosn't work

Regards

Do your explorers have RSSI LEDs? Are they lighting up when the transmission is sent?

1 Like

Hello Mr. Jack Christense
many thanks for your replay I do really appreciated
the explorer is connected to arduino and it has RSSI LED but it is not lighting up

Regards

Then the transmission is not getting through. Look at the "Series2_Tx" example that comes with the XBee library. Implement some similar code to read the ZBTxStatusResponse. Use getDeliveryStatus(), assign it to a variable, and print it out. Status codes are as below.

I might slow down the transmissions to maybe every 8 or 10 seconds until I got it working. Also just FYI, setting DH and DL in API mode has no effect, the address is in the ZBTxRequest packet.

00110 #define     SUCCESS 0x0
00111 #define CCA_FAILURE 0x2
00112 #define INVALID_DESTINATION_ENDPOINT_SUCCESS 0x15
00113 #define     NETWORK_ACK_FAILURE 0x21
00114 #define NOT_JOINED_TO_NETWORK 0x22
00115 #define     SELF_ADDRESSED 0x23
00116 #define ADDRESS_NOT_FOUND 0x24
00117 #define ROUTE_NOT_FOUND 0x25
00118 #define PAYLOAD_TOO_LARGE 0x74

before I try your suggestion I'd like to mention that I erased #include <NewSoftSerial.h> from the original code from the example
is it ok ?

because I tried so many times to add NewSoftSerial library and the arduino didn't accept it and send me error message about it, so I decided to remove it

I have inserted this to the end of the "void loop"

void loop(){
.
.
.
int x=txStatus.getDeliveryStatus();
if (x) {
Serial.println(x,HEX);
}
}

and it gave me: 53
but I didn't fine the related problem !!

Regarding NewSoftSerial, the XBee library uses hardware serial and the XBee must be hooked to the hardware serial pins. Is that how you have it connected? (That said, there should be no problem using NewSoftSerial for other devices.)

You have the XBee product manual? There is no status code of 0x53, see page 110. So something is fishy, I'd double check my code.

I connected the TX, RX, POWER, GND between Arduino and XBee
I work with the code with out the "NewSoftSerial" library and I'd like to know if it is ok ?

I have checked the status and I didn't find any related one to mine

so what I'm asking if there is a simple code and may be tested that any body could post it to me, I will be greatfull

You must have some sort of installation issue, including the NewSoftSerial library should cause no problem. But the XBee library does not use it, like I said.

Probably the Series2_Rx and Series2_Tx examples are about as simple as it gets. Haven't played with them myself, but I might try that if I were you.

Here is a blog post of mine that may also be useful.

thanks for you support I'll try my best and get back with good results

Regards

I tried the code in the xbee library
the TX and RX code for seirs 2 and nothing worked the cooedinator keep sending but the router does not respond
any help please ?

I Have tried this thing
I have one XBee in API as coordinator, and one router XBee in API

I connected the arduino to the router and installed the following code on arduino

#include <XBee.h>

uint8_t text[] = {'H', 'e', 'l', 'l', 'o'};

XBee xbee = XBee();
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013a200, 0x407a3903);
ZBTxRequest zbTx = ZBTxRequest(remoteAddress, text, sizeof(text));

void setup () {
delay(1000);
xbee.begin(9600);
}

void loop () {
xbee.send(zbTx);
delay(3000);
}

the serial output of the arduino is:

7E 00 0F 10 01 00 7D 33 A2 00 40 7D 5E 70 39 FF FE

Which is has no response on coordinator !!

So I tried the following, I tried to communicate using direct I/O on the two XBees and I has a API frame communication from the router to the coordinator which is :

7E 00 12 29 00 13 A2 00 40 7C 48 1E 4C 46 01 01 00 01 00 00 01 00

and communicate well :slight_smile:
I Think the problem is in the code on arduino it should be edited to send a frame such as the second one to establish communication

I’m I right ??
I think the following command should modified

ZBTxRequest zbTx = ZBTxRequest(remoteAddress, text, sizeof(text));

If yes, How to make that ??

P.S: the XBees configuration as follow
Receiver : COORDINATOR API, Version 21A7 , DH=0, DL=FFFF
Transmetter : ROUTER API, Version 23A7 , DH=0 , DL=0
AND THE SAME PAN ID
regards

Hi Fouad,

I have a similar issue.

I have debugged the sended frame from arduino and direct I/O, and they aren't the same.
I think the problem isn't in 'ZBTxRequest' function, instead it is in the XBee library 'send' function, where the frame is created.

I'm investigating this!

Regards.

In 'sendByte' function, when the it calculates the checksum it has to be:
"checksum = 0xff - (checksum & 0xff);"

But communication still fails!

Hi

has anyone found a solution to this problem?

I have the same problem....

I have 2 Xbee PRO S2B configured with API firmware (one is Coordinator and the other is Router) as shown here: GitHub - andrewrapp/xbee-api: Java library for communicating with XBee radios

I must to do the following communication Arduino-> XBee COORDINATOR -> Xbee ROUTER -> PC (java)
--------------------------------------------------------------------------------------------------------------------------------------------------------->
To do this, I have the Xbee COORDINATOR connected to an Arduino One using the Xbee Explorer Regulated. In the arduino I put the following program: GitHub - andrewrapp/xbee-arduino: Arduino library for communicating with XBee radios in API mode (changing the destination address of my Xbee ROUTER ). The LED blinks when arduino sends and twice when no response so everything seems to be working properly. Tx Led in Xbee Explorer Regulated also blink at the same time.

In the destination, I have connected the Xbee ROUTER to a PC using the Xbee Usb Explorer. On the PC I have running the following Java application (ZNetReceiverExample.java of Xbee-API rapplogic).

But nothing happens at the receiver (PC). The java application receives nothing :frowning:
I tried to reset everything but nothing happens...

At the receiver (PC) I tried to read directly from the serial port with Hyperterminal or X-CTU [Arduino->XBee COORDINATOR->Xbee ROUTER->PC(Hyperterminal)] to know if the problem was the Java application, but neither happens, I dont receive anything from the serial port.

--------------------------------------------------------------------------------------------------------------------------------------------------------->
To try other things, I tried to establish communication in the other direction, using PC as sender instead an Arduino One: PC (java)->XBee COORDINATOR->Xbee ROUTER->PC (Hyperterminal)

Now, I connected the Xbee COORDINATOR to the PC using another Xbee Usb Explorer. On the PC I have the following java application (ZNetSenderExample.java Xbee-API rapplogic)GitHub - andrewrapp/xbee-api: Java library for communicating with XBee radios

In the destination, I have connected the Xbee ROUTER to a PC using the Xbee Usb Explorer. I tried to read directly from the serial port with Hyperterminal and IT WORKS!
I receive a lot of strange characters and in the middle the word: "Xbee" that is the payload send at the source.

--------------------------------------------------------------------------------------------------------------------------------------------------------->

So it seems that when I have the following configuration [Arduino-> XBee COORDINATOR -> Xbee ROUTER -> PC (java)], the Arduino One is not sending anything and the problem is Arduino????

Someone could help me????

Thanks

Found a solution!

I was having the same problem as Fouad and receiving a frame almost identical to "7E 00 0F 10 01 00 7D 33 A2 00 40 7D 5E 70 39 FF FE"

Turns out that I needed to disable escaping characters on the commander xbee. (Set AP to 1)

Now I receive the frame with the proper addressing.

Let I hope this helps

Hi, i have been working with xbee s2 the past few weeks with AT mode and i manage to have them communicate. Now am trying to do the same but in API mode using the xbee-api library. but no luck. the transmitter works fine but the receiver is not working. . any answers thanks :slight_smile: