Arduino + xbee + api

well i used the xbee.h library's example tx program, and i only get an error :frowning:

initial setup

connected an xbee to my laptop

ATMY FFFF
ATAP 2

here is the code on my arduino

i jus changed the address in txrequest to FFFF
and the value to be transmitted to r (pin5)

#include <XBee.h>

XBee xbee = XBee();

unsigned long start = millis();

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

// with Series 1 you can use either 16-bit or 64-bit addressing

// 16-bit addressing: Enter address of remote XBee, typically the coordinator

Tx16Request tx = Tx16Request(0xFFFF, payload, sizeof(payload));

TxStatusResponse txStatus = TxStatusResponse();

int pin5 = 0;

int statusLed = 11;
int errorLed = 12;

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);
  
  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 = 20;
      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, 50);
             } else 
             {
            	// the remote XBee did not receive our packet. is it powered on?
             	flashLed(errorLed, 3, 500);
             }
        }      
    } 
else
    {
      // local XBee did not provide a timely TX Status Response -- should not happen
      flashLed(errorLed, 2, 50);
    }
    
    delay(1000);
}

when i run the code, my arduino serial monitor displays garbage value, the same one over and over again--> (~ yE- ~ yE- ~ yE-)

is the abve changes sufficient or is there something i missed out on???