Go Down

Topic: XBee Payload Formatting (Read 1 time) previous topic - next topic


I'm trying to setup a payload to transmit over XBee using the Arduino XBee google code library. I have a bunch of int values that I want to transmit in groups with some sort of delimiter. I'm not really sure how I should go about formatting the payload. I don't mind if just the raw data transmits because I'm reading it into a Java program on the other end that can format it all correctly. Any help/suggestions? Thanks!
Code: [Select]

void transmitData(){
  XBee xbee = XBee();
  for(int i=1; i<=eeCount; i++){
    toGet = i;
    uint8_t payload[] = {};
    payload[0] = highByte(curActVal);
    payload[1] = lowByte(curActVal);
    payload[2] = ' ';
    payload[3] = highByte(curMon);
    payload[4] = lowByte(curMon);
    //payload[5] = "/";
    payload[6] = highByte(curDay);
    payload[7] = lowByte(curDay);
    //payload[8] = "/";
    payload[9] = highByte(curYear);
    payload[10] = lowByte(curYear);
   // payload[11] = ' ';
    payload[12] = highByte(curHour);
    payload[13] = lowByte(curHour);
    //payload[14] = ":";
    payload[15] = highByte(curMin);
    payload[16] = lowByte(curMin);
    Tx16Request zbTx = Tx16Request(0x1234, payload, sizeof(payload));


Code: [Select]
    uint8_t payload[] = {};
The lack of a value in the [] means that you want the compiler to figure out the size of the array based on the number of initializers present.

You are not providing very many initializers, so your array size will be relatively small.

Code: [Select]
    payload[0] = highByte(curActVal);
Oops, you just wrote beyond the end of your array.

Aside from this little issue, what's the problem with what you are doing?
The art of getting good answers lies in asking good questions.


So I updated to
Code: [Select]

uint8_t payload[255] = {};

And are you saying that payload[0] is not valid? Isn't the values from 0 to 254?



PaulS was simply saying that as you had declared your array to be of zero size, writing on any byte of it would be out of bounds. In the case you have posted, you don't need it to be so big as 255 (and memory is tight on Arduino) 17 would be enough.

Go Up