Xbee Api connection

Hi

I have a kind of small problem, but I can’t get it solved.

I’m doing a wireless sensor network with accelerometer and on sensor side I need a microcontroller to do some calculations and time stamping. I’m using Xbee series 2 ZB modules to do wireless communication. I have USB explorer on computers side to collect data which I’m using Processing.

Because of Processing I need API mode on at least coordinator side, but also I think I need it on microcontroller’s side. For microcontroller I’m using Arduino mini Pro.

The problem is that I cannot get ANY communication on API mode.

I’m using on Arduino example code from http://code.google.com/p/xbee-arduino/ to transmit data and I’m using http://www.faludi.com/examples/xbee-api-library-for-processing/ on explorers side.

I have configured PANID
Channel on coordinator and channel scan on router. I have also enabled eternal joining (FF) on coordinator. The baud rate is same on both and API mode is 2, which is API mode with escaping. Also node identifiers are set.

I have connection from Arduino to Xbee and from computer to Xbee, but I cannot get anything transferred. If I change to AT mode and make a code to send it just trough serial, it transmits.

I have read "Building Wireless Sensor Networks" by Robert Faludi but it doesn’t cover the choice to use Arduino on sensor side.

One question is that to do just basic data transfer on API mode, what is the wiring for this. I have used VCC ground TX and RX. Is that Right or do I need Xbee Shield or anything else? I have ordered shields, but they haven’t arrived yet.

Second is that do I need to make any config to the codes for AT commands to make it work? I mean that do I need to force channel or any other config?

Third is that if those two isn’t right questions, then how I can get those to communicate.

If someone could help me I would be very happy also if I can figure out it myself I will post it here.

--
Thanks Helkku

Have you tried to set the sensor XBee to sample and send the data automatically? You can set up which pins to sample and at what rate you want them sampled.

wade

What do you mean by "sample and send the data automatically"? Do you mean that connect sensor directly to Xbee IO-ports or connect Arduino to IO-ports and let the Xbee automaticly send the data?

Yes you can use the ADC's on the XBee to measure the accelerometer values and then report these values back to the coordinator in a regular defined fashion.
wade

I know that I can, but there is a problem for that approach. I need to calculate exact values, have a error filter and I need to have exact timestamps from data. There will be few sensors which all need to do that so I cannot do that with straight approach.

I’m pretty sure that problem is that I don’t have shields. Those haven’t arrived yet, so I’m going to wait until I get those.

Hi,

I'm trying to use the XBEE library to work in API mode, but even programming my arduinos (plus xbee shield) with these api examples, it doesn't work.

I'm reading the library but I've looked that I can only send uint8_t data, and what if I want to send a string? How can I do this??

If I only want send and receive a packet with some data, how can I do this more simply??

I'm reading the library but I've looked that I can only send uint8_t data, and what if I want to send a string? How can I do this??

You lie to the compiler, using a cast.

char stuffToSend[] = "I want to send this";

functionThatExpectsUint8_t((uint8_t)stuffToSend);

Thanks!!

But this isn't the case, it isn't calling a function, it's just a cast. For example, if it works, I'll do "uint8_t mSG = (uint8_t) char data".

It won't work. The cast I'm trying to do didn't work because the compiler doesn't know how to convert them. That's the conclusion I get.

Regards.

It won't work. The cast I'm trying to do didn't work because the compiler doesn't know how to convert them. That's the conclusion I get.

Pssst. Quit waving your hands around and post some code.

Ok,

I modified a bit my code, but it doesn't work yet. I need to send and receive a simple message, but I want to use API mode to check (ACK, like TCP) the receivement of the message, so sender can re-send the message in case the message will be loose.

I write my code below, so if somebody could check it and tell me a tip, it would be great.

SEND:

#include <XBee.h>

XBee xbee = XBee();

uint8_t payload[] = { "OK" };
int pin = 13;
//char sendMsg[] = "OK";

XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x10101010);    //@MAC coordinator
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

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

  xbee.begin(57600);
}

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.");

  if (xbee.readPacket(5000)) {
    Serial.println("\tHaving Response.");
    	
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);
      Serial.println("\t\tTX STATUS");
      
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        Serial.println("\t\t\tSUCCESS");
      }
    }
  } 

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

RECEIVE:

#include <XBee.h>

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();

ZBRxResponse rx = ZBRxResponse();

int pin = 13;
uint8_t *data;

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

  xbee.begin(57600);
}

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("\tThere's RX packet.");
      xbee.getResponse().getZBRxResponse(rx);
      data = rx.getData();
    }
  }
  
  Serial.flush();
  delay(500);
  digitalWrite(pin, LOW);
  delay(5000);
}

I modified a bit my code, but it doesn't work yet.

That certainly narrows down the scope of the problem. You have the XBees, configured in some mysterious way. You have the shields with blinking lights (or not). You have the serial output. All we have is the code.

Uppsss, sorry!

I'll tell you my xbee configuration.

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]

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).
This is why I said 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.

Hi,

Paul or someone else, does anybody could help me, please??

I don't understand why xbee-library from google project doesn't work. The modules are associated, and I swear that router sends right the message, but coordinator can't read anything.

Regards.

The suspense is killing me! What happens when you run your code? What's the serial output? Any activity on the XBees?

Captures are here, just checked them. They are atached.

The code I used is the one above.

Nothing more happens, they associated between themselves.

One problem might be the Serial.print()s which send output directly to the XBee attached to the hardware serial port, potentially messing up the api message that is also sent via the serial port.

Hi,

thanks!!

But I have been doing some tests and I think the reason is another one.

I set the xbee shields in USB mode, and open two x-ctu, with the 'digi API fram maker' web app, I created also the send frame as the receive one, and send it by x-ctu terminal. And how surprise!! It works!!

So, I realised that the problem is in the library or the examples, because I only tried to use them.

So you've tried them in USB mode, which eliminates the interference from the Serial.print() calls, and the connection works and you can send packets.

But you think that this is proof that it is not the Serial.print() calls that are causing the problem?

I don't follow your logic. What do you think is the problem?

Ok, I'll try to explain my logic, sure I'm wrong but if Serial.print is the problem I don't understand why it is happening.

I think that if I'm using xbee modules in api 2 mode, and also I'm working with xbee library, so Serial.print doesn't must interfere with xbee.send or xbee.readPacket instructions. They must work in a different way in this case.

And one more doubt I have is when I launch 'xbee.send' from one module, the other doesn't receive anything even when it sends to MAC address.

It is a strange behaviour and I' m forgetting something but I haven't caught the point.

Regards.

PD: Now I'm trying to receive the packet without any 'Serial.print' instructions on the sender side and only one in the receiver side to show data however there's no response, so it never shows anything. Instructions like 'readPacket', 'xbee.getResponse().isAvailable()', or this one 'xbee.getResponse().getApiId() == ZB_RX_RESPONSE' never works fine, and I think there would be the problem.

One more thing... I work with xbee shield so, when I upload my code to arduino, I have to switch the jumpers from xbee shield to xbee position. Is this right??

Or is there another configuration to improve the communication?? (I tried different ones but even though it didn't work).