XBee API mode help

arduinoxbee

I am not sure if this is a right place to put this question but if anyone is familiar with XBee and can help me with this problem, I highly appreciate your help.

I have two XBees, one configured as coordinator API and another configured as router API.

I have attached those two XBees with two arduinos just to test communication between them. The code for each one is very simple.

Code in arduino hooked to coordinator XBee

Description: This will simply check button press. Upon press it will send ZigBee transmit request frame.

int BUTTON1 = 3;

void setup()
{
    pinMode(BUTTON1, INPUT);
    Serial.begin(9600);
}

void loop()
{
    if (digitalRead(BUTTON1) == HIGH)
    {
        sendData();
    }
}

void sendData()
{
    Serial.write(0x7E);

    Serial.write(0x00);
    Serial.write(0x16);

    Serial.write(0x10);

    Serial.write(0x01);


    Serial.write(0x00);
    Serial.write(0x13);
    Serial.write(0xA2);
    Serial.write(0x00);
    Serial.write(0x40);
    Serial.write(0x8C);
    Serial.write(0xC6);
    Serial.write(0xD4);

    Serial.write(0x20);
    Serial.write(0x01);

    Serial.write(0x00);

    Serial.write(0x00);

    //data start  
    Serial.write(0x54);
    Serial.write(0x78);
    Serial.write(0x44);
    Serial.write(0x61);
    Serial.write(0x74);
    Serial.write(0x61);
    Serial.write(0x30);
    Serial.write(0x41);

    Serial.write(0x13);

    delay(10);

}

Next is the code for arduino hooked to router XBee.

Description: This simply scans "0x54" byte and if it is there then lights up a LED. As you can see, coordinator sends this byte 0x54 along with other bytes.

int BELL = 5;

void setup()
{
    pinMode(BELL, OUTPUT);
    Serial.begin(9600);
}

void loop()
{

    if(Serial.available() >= 25)
    {
        if(Serial.read() == 0x7E)
        {
            for(int i=0;i<24;i++)
            {
                if(Serial.read() == 0x54)
                {
                    digitalWrite(BELL, HIGH); 
                }
            }
        }
    }
}

I would like to add that, when I turn on serial monitor, and then press the button, the serial monitor displays correctly what data was passed. Also tx lights up. So my assumption is that the problem is in the router not getting the data rather than coordinator not sending the data. I have been trying to hunt this problem for couple of hours now with no success. Any help is highly appreciated!

Best Answer

I don't think your checksum byte is correct.

Adding up all the bytes from after the length bytes to before the checksum byte gives me 0x604. 0xff - 0x04 = 0xfb

You should write a method to implement sending (and receiving too), e.g.

struct xBeePacket {
   unsigned int dest_address;
   unsigned char api_id;
   unsigned char frame_id;
   unsigned char options;
   unsigned char data[100];
   unsigned int length;
}

void send_message(xBeePacket* p)
{
   unsigned char checksum = 0;

   Serial.write(0x7E);
   Serial.write((byte)(length>>8));
   Serial.write((byte)(length & 0x00ff));

   Serial.write(p->api_id);  checksum += p->api_id;
   Serial.write(p->frame_id);  checksum += p->frame_id;

   Serial.write((byte)(p->dest_address >> 8));  
   checksum += (byte)(p->dest_address >> 8);
   Serial.write((byte)(p->dest_address & 0x00ff));  
   checksum += (byte)(p->dest_address & 0x00ff);

   Serial.write(p->options);  checksum += p->options;

   for (int i = 0; i < p->length; i++)
   {
       Serial.write(p->data[i]);  checksum += p->frame_id;
   }

   Serial.write(0xff - checksum);
}

Hoep this gets you started.