ZB API examples

Hi,

I have program my xbees S2B to API mode (2, with escape character), with ‘join verification’ for the routers, and letting the coordinator to adjust the rest of the parameters.

I look how the modules associate between them, but I can’t wacth any communication.

I’m using next code:

SEND:

#include 

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

uint8_t payload[] = { "OK" };

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x10101010);    //@MAC coordinator
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int pin = 13;
//char sendMsg[] = "OK";
//___________________________________________________________________________________________

void setup() {
  pinMode(pin, OUTPUT);

  xbee.begin(57600);
  Serial.println("
	... XBee - ZB ...
");
}
//___________________________________________________________________________________________

void loop() {   
  digitalWrite(pin, HIGH);
  
//  payload = (uint8_t)sendMsg;
//  Serial.print("Send Message: [");
//  Serial.print(payload);
//  Serial.println("]");
  
  xbee.send(zbTx);
  Serial.println("Sending TX packets.");

  // wait up to 5 seconds for the status response
  if (xbee.readPacket(5000)) {
    Serial.println("	Having Response.");
    	
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);
      Serial.println("		TX STATUS");
      
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        Serial.println("			SUCCESS");
      }
    }
  } 

  Serial.flush();
  delay(500);
  digitalWrite(pin, LOW);
  delay(5000);
}


RECEIVE:

#include 

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

int pin = 13;
uint8_t *data;
//___________________________________________________________________________________________

void setup() {
  pinMode(pin, OUTPUT);

  // start serial
  xbee.begin(57600);
  Serial.println("
	... XBee - ZB ...
");
}
//___________________________________________________________________________________________

void loop() {
  digitalWrite(pin, HIGH);

  xbee.readPacket();
  Serial.println("Checking RX packets.");

  if (xbee.getResponse().isAvailable()) {
    Serial.println("There's some RX.");

    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
      Serial.println("	There's RX packet.");
      xbee.getResponse().getZBRxResponse(rx);
      data = rx.getData();
    }
  }
  
  Serial.flush();
  delay(500);
  digitalWrite(pin, LOW);
  delay(5000);
}

Am I doing something wrong??

Regards.

Hi,

I’ll tell you my xbee configuration for more accurate.

[i]COORDINATOR - Receive data
PAN ID: 0 [coordinator assigns an Operating PAN-ID]
Scan Channel: 1FFE
Node Time: FF
Channel: x [coordinator assigns the Operating channel]
API Mode: 2
Baud Rate: 6 [57600]

ROUTER - Send data
PAN ID: 0 [assigned by coordinator]
Scan Channel: 3FFE
Channel Verification: 1
Channel: x [assigned by coordinator]
API Mode: 2
Baud Rate: 6 [57600][/i]

The Operating PAN-ID and @PAN [MY] are assigned by the coordinator, and they are right, the modules have the same Operating PAN-ID, channel, and their @PAN are OK (coordinator has ‘0’@ and the router a different one, FAC7).
This is why I say that network are correctly established. I checked them several times, and I think they are OK.

I’m trying to learn about it, so I will be pleased if someone could help me.

  • I think these are all the necessary parameters to explain my problem, but if it will be more necessary, don’t hesitate to ask them.

Regards.

Trying the zigbee modules with the previous configuration in X-CTU application, I get the attached results.

I watched in hexadecimal, how coordinator receives the data sended by the router, but it didn’t show it well. And the checksum wasn’t the same as in the ‘digi API Frame make’.

So, the modules are associated, and they could send/receive data between them.

But when I used xbee-library from google project, it doesn’t work.

I’m in a hurry, and I tried a lot of different things, so I would appreciate any help.

Could anybody help me, please?

The problem is in ‘send side’.

  • I tried making the frames by myself and send them by x-ctu software, and it works fine!!
  • Moreover, I send the handmade frame by x-ctu (from router) and I receive it (to coordinator). [I have problems showing the entire data, but this is my fault].
  • In the other way, sending data with API and receiving it without it, it doesn’t work.

I can’t find what is the code problem. I think it might be because of the S2B chips , which are different from the S2 ones.

Sorry no one answered you (I tend to look at unanswered posts and you answered yoruself a lot :-] )

You won’t get many replies if you start out a post with gobs of “C” code which no one else has seen. In fact, from your first post I have no idea what your problem is.

I would start by looking for the TX Status back on your coordinator. So if you send ANYTHING, in 20-30 seconds you should get back the TX_STATUS packet which tells you if the sent data was ‘handed off’, or not. So if (for example) the coordinator is rejecting your APi frame, you would neither see data at your router, NOR would you see the TX Status response. Investigate that some. So to recap, even without the 2nd node/router you should be able to ‘send a frame’ and get a TX_STATUS back with an error.

As for my own work, I use API mode 1 (so no ESCAPE) and AO=1, so use frames 0x11/0x91. I don’t think that matters, just saying.

First of all, thanks for your answer!!

The code I refered is: http://code.google.com/p/xbee-arduino/

As I said before, the modules work fine, but there is a problem in the ‘send’ side. I was investigating and found that the ‘sendByte’ function didn’t build the frame in the right way, so the receiver never gets the message.

To do this, in the XBee.cpp, I modified the ‘write’ instructions in ‘sendByte’ function to ‘Serial.print(xxx, HEX)’. Then we could watch the frames by serial monitor.

The frames are wrong.

*I tried to be more explicit, but if you don’t understand anything, please, don’t hesitate to ask for more information.

Regards!

Hi,

the Xbees are setted by X-CTU to AP2.

I was checking the library (xbee-arduino) and in the XBee.cpp, at ‘sendByte’ function I substituted the ‘write’ instructions for ‘Serial.print(xxx, HEX)’, where xxx are ‘ESCAPE’, ‘b^20’ or ‘b’. And it shows the frame to send, but this frame is wrong (I know that when a byte is ‘00’, it only shows one ‘0’).

I couldn’t tell you if it because of the ‘Serial.print’ instruction this wrong behaviour, but how I told you before if I send the frame manually, the mesage is delivered to the receiver (in my case the coordinator).

Regards

Hi,

I’ve been doing more attempts today. I modified the ‘send’ function when it adds ‘2’ to the frame length because the didn’t be equal as the length of my frame. But it doesn’t matters it didn’t work yet.

So, I was looking for another thing, and I did the next things:

  • I was sending data in AT mode and the coordinator received it in api mode (AP2).
  • Instead an arduino mega2560 I used an arduino UNO, but the behaviour was the same as in the mega ones.
  • I tried to send the data in the API mode (AP2), and received it by coordinator in AT mode, but coordinator didn’t get anything.
  • And, finally, I checked if it could be because of the serial. How I did this? Ok, I switched the jumpers to USB mode, and tried again to send data by terminal (x-ctu). It worked! Coordinator get the message. But when I switched back the jumpers to XBEE mode, the router didn’t send anything once more.

I’m using the examples in the xbee library for API modes, and for AT modes I only printed the next message: Serial.print(“HELLO”);

So, it wouldn’t be because of the serial. But I don’t know what more to try. Also I updated the ZB modules firmwate, but they don’t work yet.

Regards

“XBee Library”

In ‘sendByte’ function, when the it calculates the checksum it has to be:
“checksum = 0xff - (checksum & 0xff);”

But communication still fails!

Hello Sir, I am facing the same problem. can you help me in this regard. How can I make xbee ardunio library frame in a right format??