Pages: [1]   Go Down
Author Topic: XBee Payload Formatting  (Read 946 times)
0 Members and 1 Guest are viewing this topic.
Milwaukee, WI
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
void transmitData(){
  XBee xbee = XBee();
  for(int i=1; i<=eeCount; i++){
    toGet = i;
    readEeprom();
    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));
    xbee.send(zbTx);
  }
}
Logged

Kyle

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    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:
    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?
Logged

Milwaukee, WI
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I updated to
Code:
uint8_t payload[255] = {};

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

Thanks!
Logged

Kyle

New Jersey
Offline Offline
Faraday Member
**
Karma: 67
Posts: 3677
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: