Pages: [1] 2   Go Down
Author Topic: Xbee Api connection  (Read 4664 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Full Member
***
Karma: 3
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Full Member
***
Karma: 3
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Rock&Roll;
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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??

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

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

functionThatExpectsUint8_t((uint8_t)stuffToSend);
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Rock&Roll;
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Rock&Roll;
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
#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:
Code:
#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);
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Rock&Roll;
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 16, 2012, 04:31:19 am by Yolco » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Rock&Roll;
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Wellington, New Zealand
Offline Offline
Sr. Member
****
Karma: 1
Posts: 404
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Rock&Roll;
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

The code I used is the one above.

Nothing more happens, they associated between themselves.


* send_capt.png (39.85 KB, 800x876 - viewed 55 times.)

* receive_capt.png (33.37 KB, 802x876 - viewed 44 times.)
Logged

Pages: [1] 2   Go Up
Jump to: