Hi, I'm trying to send the data in API mode using a pair of Arduino Duemilanove with XBee Pro series 2 equipped with my own code for XBee API frame. I've tested it using X-CTU between the end device and coordinator by assembling package manually. The result of manual input is great without error.
Here is the problem, after uploaded the sketch from Arduino IDE,then, I monitor it through X-CTU. There are packages send out from end device but the coordinator never received a single byte. Even I have tried the same package by assembling it manually.
I have tried to send the package in command mode using Arduino sketch and it worked fine. Now, API mode, I don't really sure what is the problem.
Here is the arduino sketch that I wrote for XBee API mode:
#define frameTypeSize 1
#define frameIDSize 1
#define destAddr64Size sizeof(destAddr64)/sizeof(byte)
#define destAddr16Size sizeof(destAddr16)/sizeof(byte)
#define broadcastSize 1
#define optionSize 1
#define payloadSize sizeof(payload)/sizeof(byte)
byte startDelimeter=0x7E;
byte lengthMSB=(byte)0x00;
byte lengthLSB;
byte frameType=0x10;
byte frameID=0x01;
byte destAddr64[]={0x00,0x13,0xA2,0x00,0x40,0x2D,0xB5,0x23};
byte destAddr16[]={0x00,0x00};
byte broadcast=(byte)0x00;
byte option=(byte)0x00;
byte payload[]={0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
byte checksum;
void setup(){
Serial.begin(115200);
}
void loop(){
//API Mode
//Calculate length
lengthLSB=lengthLSBCalculate();
//Calculate checksum
checksum=checksumCalculate();
//Start delimeter
Serial.write(startDelimeter);
//Length of the package
Serial.write(lengthMSB);
Serial.write(lengthLSB);
//Frame type & ID
Serial.write(frameType);
Serial.write(frameID);
//Destination Address
Serial.write(destAddr64,destAddr64Size);
Serial.write(destAddr16,destAddr16Size);
//Broadcast range
Serial.write(broadcast);
//Option
Serial.write(option);
//Payload
Serial.write(payload,payloadSize);
//Checksum
Serial.write(checksum);
delay(1000);
}
byte lengthLSBCalculate(){
return frameTypeSize+frameIDSize+destAddr64Size+destAddr16Size+broadcastSize+optionSize+payloadSize;
}
byte checksumCalculate(){
unsigned int summation=0;
for(int i=0;i<destAddr64Size;i++){
summation+=destAddr64[i];
}
for(int i=0;i<destAddr16Size;i++){
summation+=destAddr16[i];
}
for(int i=0;i<payloadSize;i++){
summation+=payload[i];
}
summation=summation+frameType+frameID+broadcast+option;
summation=(0xFF-(summation))&0xFF;
return summation;
}
Edited: This is the package sent manually.
Packages sent using the above sketch.