I want to send an integer (total count of packets) over lora. I want to use the first 10 bytes to store this integer. So for 522, first 3 bytes of the total 10 would be 53, 50 and 50. Followed by 7 zeroes. After this, I would have bytes representing my payload.
On the orther end, I would read the first 10 bytes and get the packet count that I need.
I've read a lot of posts but I can't understand how to cast an integer to byte array, if possible. I am sure there is a way more elegant way to solve this.
void sendMessage(byte payload[], int length) {
int iPt = 552;
String sPt = String(iPt);
byte aPt[10];
sPt.toCharArray(aPt, 10);
LoRa.beginPacket();
LoRa.write(aPt,10);
LoRa.write(payload, length);
LoRa.endPacket();
}
What I'd like to get on the receiving end is: 53 50 50 0 0 0 0 0 0 0.
What I am getting is 53 50 50 0 (I guess this 0 is the null termination?)
I appreciate any help. Thanks!
write