Putting Xbee API i/o data sample into variable

Here is a sample API format for Zigbee I/O Data Sample

7E0014920013A20040522BAA7D840101001C0200140225F5

We can tell the frame type is 92 and the data length is 14 (Both values are in Hex)

We are trying to capture this API data stream without using library as assistance, using serial.read() that reads 1 byte at a time. We created a “for loop” and an “array” to store incoming data, however the array is not storing “7E”, “00”, “14” … so on but in decimal format.

Any idea to have (1) the value in array converted from (Dec to Hex) and (2) Compose everything from array to another string variable? Want to achieve something like this below?

String APIData;
APIData = (payload[0], HEX) + (payload[1], HEX) + (payload[2], HEX) + (payload[3], HEX) + (payload[4], HEX)........

// APIData should contains "7E7E00149200....."

Is this doable?

Thanks, Team BTF

Found this thread from within forum which is very close to what I am looking for.

http://forum.arduino.cc/index.php?topic=213493.0

Advice, input anyone?

Cheers, Team BTF

Here is a sample API format for Zigbee I/O Data Sample

7E0014920013A20040522BAA7D840101001C0200140225F5

Wrong.

7E 00 14 92 00 13 A2 00 40 52 2B AA 7D 84 01 01 00 1C 02 00 14 02 25 F5
Right.

The fact that you can’t be bothered to show the separation between values doesn’t meant that it doesn’t exist.

We are trying to capture this API data stream without using library as assistance, using serial.read() that reads 1 byte at a time. We created a “for loop” and an “array” to store incoming data, however the array is not storing “7E”, “00”, “14” … so on but in decimal format.

Because the incoming data isn’t “7E”, “00”, “14”, etc. The incoming bytes are 0x7E, 0x00, 0x14, etc.

A String is NOT an array.

APIData = (payload[0], HEX) + (payload[1], HEX)...

You should look up the comma operator to see what (payload[0], 16) actually returns. It is most certainly NOT returning “7E” when payload[0] is 0x7E.

Is this doable?

Of course. But, you are not even starting from the right spot, let alone going the right direction.

Off to http://snippets-r-us.com with you and your snippets.

Of course. But, you are not even starting from the right spot, let alone going the right direction.

Thanks for the pointer. We think we got our variable declaration wrong after re-visited the Arduino reference section.

http://arduino.cc/en/Reference/HomePage

The incoming bytes are 0x7E, 0x00, 0x14, etc.

In this case, would byte or char datatype more make sense being used first to hold the incoming data?

Cheers, Team BTF

In this case, would byte or char datatype more make sense being used first to hold the incoming data?

To whom? If all the values are less than 0x7F, it doesn't matter. Since you can't guarantee that, byte is more appropriate. char would be, if the data was ASCII values (but, it isn't).

Hello Team

String apiData;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int dataSize = 12;
  apiData = "";

  byte payLoad [dataSize];

  payLoad[0] = 0x7E;
  payLoad[1] = 0x00;
  payLoad[2] = 0x12;
  payLoad[3] = 0x92;
  payLoad[4] = 0x00;
  payLoad[5] = 0x13;
  payLoad[6] = 0xA2;
  payLoad[7] = 0x00;
  payLoad[8] = 0x40;
  payLoad[9] = 0xA8;
  payLoad[10] = 0x2F;
  payLoad[11] = 0xF2;

  for (int i = 0; i<dataSize; i++) {
    apiData.concat(payLoad[i]);
  }
  
  Serial.println(apiData); // This will print 12601814601916206416847242
    
}

Question is, what is needed so that apiData contains a true String with “7E 00 12 92 00 13 A2 00 40 A8 2F F2” ?

Still puzzled.

Team BTF

Question is, what is needed so that apiData contains a true String with "7E 00 12 92 00 13 A2 00 40 A8 2F F2" ?

Why do you want to take 12 bytes and make a 35 character String from them?

You can create a String from a byte, using whatever base you want. You can NOT expect that the String class will know what base you used when defining the value stored in the byte. What is actually stored in the byte is binary data.

If you want the spaces, YOU have to add them.