Pages: [1]   Go Down
Author Topic: data arrives, but always the same. Digimesh  (Read 556 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I thought I already made this to work but I don't know what happends.

I am using digimesh mode for series 1. here you can find the library: http://dl.dropbox.com/u/40929079/XBee.tar.gz Luk156 gave me this link.

For now, I am sending always the same data. I haven't got the sensors yet. But, it doesn't matters what I send, I always receives 19, 162.

This is my code:

TX:  (it is the series 1 tx example, modified to match for DM mode)
Code:
#include <XBeeDM.h>
#include <SoftwareSerial.h>

XBee xbee = XBee();

unsigned long start = millis();

// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[2];

XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x4080E273);
DMTxRequest tx = DMTxRequest(addr64, payload, sizeof(payload));

DMTxStatusResponse txStatus = DMTxStatusResponse();

int pin5 = 0;

int statusLed = 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);
 
  xbee.begin(9600);
}

void loop() {
   // start transmitting after a startup delay.  Note: this will rollover to 0 eventually so not best way to handle
    if (millis() - start > 15000) {
      // break down 10-bit reading into two bytes and place in payload

      pin5 = 140; /what I send
      payload[0] = pin5 >> 8 & 0xff;
      payload[1] = pin5 & 0xff;
      xbee.send(tx);

      // flash TX indicator
      delay(3000);
    }
 
    // after sending a tx request, we expect a status response
    // wait up to 5 seconds for the status response
    if (xbee.readPacket(5000)) {
        // got a response!

        // should be a znet tx status           
    if (xbee.getResponse().getApiId() == DM_TX_STATUS_RESPONSE) {
       xbee.getResponse().getDMTxStatusResponse(txStatus);
   
       // get the delivery status, the fifth byte
           if (txStatus.getDeliveryStatus() == SUCCESS) {
            // success.  time to celebrate
              flashLed(statusLed, 5, 1000);
           } else {
            // the remote XBee did not receive our packet. is it powered on?
              flashLed(statusLed, 3, 1000);
           }
        }     
    } else if (xbee.getResponse().isError()) {
      //nss.print("Error reading packet.  Error code: "); 
      //nss.println(xbee.getResponse().getErrorCode());
      // or flash error led
    } else {
      // local XBee did not provide a timely TX Status Response.  Radio is not configured properly or connected
      flashLed(statusLed, 2, 1000);
    }
}

RX: (same as upper code, Rx series 1 modified) I changed a little bit more, just to print received data by Serial.
Code:
#include <XBeeDM.h>
#include <SoftwareSerial.h>

XBee xbee = XBee();
DMRxResponse dmRx = DMRxResponse();
uint8_t option = 0;
int data = 0;

uint8_t analogH1;
  uint8_t analogL1;

void setup() {
  Serial.begin(14400);
 
  // start serial
  xbee.begin(9600);
 
}
 
// Reading packets to find RxDM
void loop() {
    //Serial.println("empezamos");
    xbee.readPacket();
        if(xbee.getResponse().isAvailable()) {

       if (xbee.getResponse().getApiId() == DM_RX_RESPONSE){
                xbee.getResponse().getDMRxResponse(dmRx);
        option = dmRx.getOption();
                analogH1 = dmRx.getData(0);
                analogL1 = dmRx.getData(1);
                //data = analogL1 + (analogH1* 256);
               
                Serial.print("Received: ");
                Serial.println(analogH1);       
                Serial.println(", ");
                Serial.println(analogL1);
      }
      else{
      Serial.println("Doesn't receive which we were waiting for");   
      }
    }
    else if(xbee.getResponse().isError()) {
      //nss.print("Error reading packet.  Error code: "); 
      //nss.println(xbee.getResponse().getErrorCode());
      // or flash error led
    }
}

I wrote data = /*analogL1 +*/ (analogH1); //* 256); because in one webpage I found that data is broken in two parts to be sended and you have to join it before reading the real value. I also tried but I always read: 5026. If you do 162 + 19*256 = 5026. Always same value.


I checked xbee.h and .cpp looking for a 19 or 162 in code. But nothing were found. I don't know why this happends.
Logged

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

Code:
DMTxRequest tx = DMTxRequest(addr64, payload, sizeof(payload));
You are creating an instance of the DMTxRequest class, giving it the data currently in payload.

Code:
      pin5 = 140; /what I send
      payload[0] = pin5 >> 8 & 0xff;
      payload[1] = pin5 & 0xff;
Now, you put new data in payload.

Code:
      xbee.send(tx);
Now, you send the object that has the old data.

I'm not particularly surprised that you never get any new data.

P.S. It's hard to believe that that code even compiles, given that half-assed comment.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 102
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed comments to post here. I am spanish and this is an english forum.

Examples in xbee library  do that (set payload and after change it) and they work.

I will check to create tx request after introduce data in payload. I will post what happends later.

Edit: Same result creating tx request after introduce payload... Don't know why.
« Last Edit: March 22, 2012, 08:24:43 am by Suriken » Logged

Pages: [1]   Go Up
Jump to: