I have to send an intiger counter as 'num' through ZigBee(API mode) from arduino. For this purpose I have to convert this integer to String and then to uint8_t array as it is needed in API frame to transmit.
Apart from other details I've converted my integer to string like,
String str;
int num = 0;
char cstr[16];
void loop() {
num++;
str = String(num);
str.toCharArray(cstr,16);
Serial.println(cstr); // this shows the correct result, means int is converted to String correctly
uint8_t data[] = {cstr}; // passing String to uint8_t array
XBeeAddress64 addr64 = XBeeAddress64();
addr64.setMsb(0x00000000);
addr64.setLsb(0x00000000);
ZBTxRequest zbTx = ZBTxRequest(addr64, data, sizeof(data));
xbee.send(zbTx);
int count = sizeof(data);
for (int i = 0; i < count; i++) {
if (i == (count-1)) {
Serial.print(data[i]); // here it prints "104" of ASCII which is equal to "h"
}
}
}
It also transmit it as like that Serial print i.e. ('104'). Please point out if I am making any mistake and guide me if I did't doing it as required.