Sending data in api mode

Hi!

I am trying to send info between 2 arduinos (fio and freeduino) in api mode. Xbee are series 1.

I set same pan id and channel in both devices. In receiver device I set MY = FFFF as example says.
Receiver SL is 0x4068B6BC

I set xbee in sender as coordinator and the other as end device.

Code in sender (freeduino):

#include <XBee.h>
#include <NewSoftSerial.h>

/*
This example is for Series 1 XBee
Sends a TX16 or TX64 request with the value of analogRead(pin5) and checks the status response for success
Note: In my testing it took about 15 seconds for the XBee to start reporting success, so I've added a startup delay
*/

XBee xbee = XBee();

unsigned long start = millis();

// allocate two bytes for to hold a 10-bit analog reading
uint8_t payload[] = { 0, 0 };

XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x4068B6BC);
Tx64Request tx = Tx64Request(addr64, payload, sizeof(payload));

TxStatusResponse txStatus = TxStatusResponse();

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 = 135;
      payload[0] = pin5 >> 8 & 0xff;
      payload[1] = pin5 & 0xff;
      
      xbee.send(tx);

      // flash TX indicator
      flashLed(statusLed, 1, 100);
    }
  
    // 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() == TX_STATUS_RESPONSE) {
    	   xbee.getResponse().getZBTxStatusResponse(txStatus);
    		
    	   // get the delivery status, the fifth byte
           if (txStatus.getStatus() == SUCCESS) {
            	// success.  time to celebrate
             	flashLed(statusLed, 5, 500);
           } else {
            	// the remote XBee did not receive our packet. is it powered on?
             	flashLed(statusLed, 3, 500);
           }
        }      
    } 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, 500);
    }
    
    delay(1000);
}

Code in receiver:

#include <XBee.h>
#include <NewSoftSerial.h>

/*
This example is for Series 1 XBee (802.15.4)
Receives either a RX16 or RX64 packet and sets a PWM value based on packet data.
Error led is flashed if an unexpected packet is received
*/

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle 
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();

int statusLed = 11;
//int errorLed = 12;
//int dataLed = 10;

uint8_t option = 0;
uint8_t data = 0;

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);
 // pinMode(errorLed, OUTPUT);
 // pinMode(dataLed,  OUTPUT);
  
  // start serial
  xbee.begin(9600);
  
  flashLed(statusLed, 3, 50);
}

// continuously reads packets, looking for RX16 or RX64
void loop() {
    
    xbee.readPacket();
    
    if (xbee.getResponse().isAvailable()) {
      digitalWrite(13,HIGH);
      delay(3000);
      digitalWrite(13,LOW);
      // got something
      
      if (xbee.getResponse().getApiId() == RX_16_RESPONSE || xbee.getResponse().getApiId() == RX_64_RESPONSE) {
        // got a rx packet
        
        if (xbee.getResponse().getApiId() == RX_64_RESPONSE) {
                
                xbee.getResponse().getRx64Response(rx64);
        	option = rx64.getOption();
        	data = rx64.getData(0);
                digitalWrite(13,HIGH);
                delay(3000);
                digitalWrite(13,LOW);
        }
        
        // TODO check option, rssi bytes    
        flashLed(statusLed, 1, 10);
        
        // set dataLed PWM to value of the first byte in the data
        if(data == 135){
          digitalWrite(13,HIGH);
          delay(500);
          digitalWrite(13,LOW);
          delay(500);
          digitalWrite(13,HIGH);
          delay(500);
          digitalWrite(13,LOW);
          delay(500);
        }
      //  analogWrite(statusLed, data);
      } else {
      	// not something we were expecting
        flashLed(statusLed, 1, 25);    
      }
    } else if (xbee.getResponse().isError()) {
      //nss.print("Error reading packet.  Error code: ");  
      //nss.println(xbee.getResponse().getErrorCode());
      // or flash error led
    } 
}

I tried with AP = 0 and AP = 1. In AP = 0, fio's rssi led, lights. With AP = 1, nothing happends.

The only answer Sender says is 2 blinks. So, it doens't receive anything.

Any idea? Something wrong? I need to configure anything else?

I need to configure anything else?

Where did you get the idea that you needed to change SL on one XBee?

You need to set just three things on each XBee - PAN ID, DL, and MY. DL on one XBee needs to match MY on the other, and neither value should be 0.

I didn't change SL. I put on code the original SL. reading the example provided by Xbee librarie, I see I have to put SH and SL on address. It says also that MY address on receiver has to be FFFF.

I don't understand the idea about to set DL = MY on the other. If I want to do a multipoint network, I can't do that. I will loose possibilitie of send to multiple antennas. I guess it will be ok for point to point connection but for this kind of network...

I have looked for any example but I didn't find anything which shows xbee configuration.

I am trying again. I don't know how to set xbees. I bricked one. I restored it again, buff...

I have the upper code. What parameters do I have to set in xbees? My target is having a network like this:

I would want to know the parameters for one point and the multipoint node.

I read a lot of webpages but allways I see code or complete programs but anything about xbee configuration.