XBee communication

Hi
I am trying to make this program work but having trouble

I have two arduino with xbee shield and xbee series 2 modules.

Both are configure like in this page http://code.google.com/p/xbee-api/wiki/XBeeConfiguration

So one coordinator and one end point both api and both AP=2

test the configuration and it work.

Now I have this program on my coordinator

//Programme pour COORDINATEUR

#include <XBee.h>

#define TERM_CHAR '\n'
#define BUF_LEN   30

XBee xbee = XBee();

XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

char ReceivedData[10];

void ReceiveData()
{
  xbee.readPacket();
    
    if (xbee.getResponse().isAvailable()) {
      // got something
      
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        // got a zb rx packet
        
        // now fill our zb rx class
        xbee.getResponse().getZBRxResponse(rx);
            
        if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
            // the sender got an ACK
        } else {
            // we got it (obviously) but sender didn't get an ACK
        }
        // set dataLed PWM to value of the first byte in the data
        for(int i=0; i < rx.getDataLength(); i++) {

           ReceivedData[i] = (char)rx.getData(i);

        }
        Serial.println(ReceivedData);
        
      } else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) {
        xbee.getResponse().getModemStatusResponse(msr);
        // the local XBee sends this response on certain events, like association/dissociation
        
        if (msr.getStatus() == ASSOCIATED) {
          // yay this is great.  flash led
          Serial.print("ASSOCIATED");
        } else if (msr.getStatus() == DISASSOCIATED) {
          // this is awful.. flash led to show our discontent
          Serial.print("DISASSOCIATED");
        } else {
          // another status
        }
      } else {
      	// not something we were expecting
      }
    } else if (xbee.getResponse().isError()) {
      Serial.print("Error reading packet.  Error code: ");  
      Serial.println(xbee.getResponse().getErrorCode());
    }
}

void SendData (char SendString[], String Destination)
{
  char payload[10];
  strncpy(payload, SendString, 9); 

  /** 
  * Sh – 13A200 Sl – 408AD157 Coordinateur
  *
  * Sh – 13A200 Sl – 408AD159 Pasteur
  *
  * Sh – 13A200 Sl – 4081A8ED Salle 1
  */
  XBeeAddress64 addr64 = XBeeAddress64(0x13A200, 0x4081A8ED);
  
//  if (Destination == "SALLE1")
//  {
//    addr64 = XBeeAddress64(0x13A200, 0x4081A8ED);
//  }
  // SH + SL Address of receiving XBee
  
  ZBTxRequest zbTx = ZBTxRequest(addr64, (uint8_t*) (payload), sizeof(payload));
  ZBTxStatusResponse txStatus = ZBTxStatusResponse();
  
  xbee.send(zbTx);
  Serial.println ("Sent");
  // after sending a tx request, we expect a status response
  // wait up to half second for the status response
  if (xbee.readPacket(500)) {
    // got a response!

    // should be a znet tx status            	
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);

      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        // success.  time to celebrate
        Serial.println ("Success tx");
      } else {
        // the remote XBee did not receive our packet. is it powered on?
      }
    }
  } else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: ");  
    //nss.println(xbee.getResponse().getErrorCode());
  } else {
    // local XBee did not provide a timely TX Status Response -- should not happen
  }
}

int i;
char incomingChar, buf[BUF_LEN];
String XBeeDestination;

void setup() {
  
  // start serial
  Serial.begin(9600);
  xbee.begin(9600);
  
}

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
  
  ReceiveData();
    
  if(Serial.available())
    {
          Serial.println ("Serial avail");
         //clean buffer
         memset(buf,'\0',BUF_LEN); i = 0;
    
         // read incoming message
         while(Serial.available())
         {
           incomingChar = (char) Serial.read();
           if(incomingChar != TERM_CHAR && i != BUF_LEN)
              buf[i++] = incomingChar;
         else
           break;
        
         delay(1); // wait for another byte
         }
//         if(strcmp(buf,"SALLE1") == 0)
//         {
//            XBeeDestination = "SALLE1";
//         }    
         if(strcmp(ReceivedData,"LedOn") == 0)
         {
            SendData("LedOn" ,XBeeDestination); //Power Led Off 
            Serial.println ("LedOn");
         } 
         if(strcmp(ReceivedData,"LedOff") == 0)
         {
            SendData("LedOff" ,XBeeDestination); //Power Led Off 
            Serial.println ("LedOff");
         }          
    }                    
    
    delay(1000);
}

and this on the end device

//Programme pour salle 1

#include <XBee.h>

// create the XBee object
XBee xbee = XBee();

XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle 
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
char ReceivedData[10];

boolean ReceiveData()
{
  xbee.readPacket();
    
    if (xbee.getResponse().isAvailable()) {
      // got something
      
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        // got a zb rx packet
        
        // now fill our zb rx class
        xbee.getResponse().getZBRxResponse(rx);
            
        if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
            // the sender got an ACK
        } else {
            // we got it (obviously) but sender didn't get an ACK
        }
        // set dataLed PWM to value of the first byte in the data
        for(int i=0; i < rx.getDataLength(); i++) {

           ReceivedData[i] = (char)rx.getData(i);

        }
        return true;
        
      } else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) {
        xbee.getResponse().getModemStatusResponse(msr);
        // the local XBee sends this response on certain events, like association/dissociation
        
        if (msr.getStatus() == ASSOCIATED) {
          // yay this is great.  flash led
          Serial.print("ASSOCIATED");
        } else if (msr.getStatus() == DISASSOCIATED) {
          // this is awful.. flash led to show our discontent
          Serial.print("DISASSOCIATED");
        } else {
          // another status
        }
      } else {
      	// not something we were expecting
      }
    } else if (xbee.getResponse().isError()) {
      Serial.print("Error reading packet.  Error code: ");  
      Serial.println(xbee.getResponse().getErrorCode());
    }
}

void SendData (char SendString[])
{
  char payload[10];
  strncpy(payload, SendString, 9); 

  /** 
  * Sh – 13A200 Sl – 408AD157 Coordinateur
  *
  * Sh – 13A200 Sl – 408AD159 Pasteur
  *
  * Sh – 13A200 Sl – 4081A8ED Salle 1
  */
  
  // SH + SL Address of receiving XBee
  XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x408AD157);
  ZBTxRequest zbTx = ZBTxRequest(addr64, (uint8_t*) (payload), sizeof(payload));
  ZBTxStatusResponse txStatus = ZBTxStatusResponse();
  xbee.send(zbTx);

  // after sending a tx request, we expect a status response
  // wait up to half second for the status response
  if (xbee.readPacket(500)) {
    // got a response!

    // should be a znet tx status            	
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);

      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        // success.  time to celebrate
      } else {
        // the remote XBee did not receive our packet. is it powered on?
      }
    }
  } else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: ");  
    //nss.println(xbee.getResponse().getErrorCode());
  } else {
    // local XBee did not provide a timely TX Status Response -- should not happen
  }
}

void setup() {
  
  pinMode(13, OUTPUT);
  xbee.begin(9600);
}

void loop() {   
  
  if (ReceiveData() == true)
  {
    if(strcmp(ReceivedData,"LedOn") == 0)
         {
            digitalWrite(13,HIGH); //Power Led Off 
         } 
    if(strcmp(ReceivedData,"LedOff") == 0)
         {
            digitalWrite(13,LOW); //Power Led Off 
         }       
  }
  char temp[] = "test";
  SendData(temp);
  delay(3000);
}

I do receive the test message on the coordinator but from my computer plug to the usb of the coordinator I am not able to make the led tun on on the end device.

How come that my command sent form the pc are not even going in the if(Serial.available()) is it because the arduino uno have only one com port and I need a
mega arduino or can i do something about it and make it work

any help would be appreciated.

I have two arduino with xbee shield and xbee series 2 modules.

Which XBee shield? How are the switches/jumpers set?

What do you see in the 2 serial monitor windows?