I know that it should be simple....but...
I have a sequence of 9 decimal byte values that I want to send, comma separated, via WiFi from a char buffer.
The receiver expect to get something like this:
{ 1, 25, 0, 148, 57, 8, 0, 82, 120 } + \0 as terminating
The problem is that I don't know how to comma separate the values .
The ASCII value of ',' is 0x2c (d44), which is a valid possible value.
Then I thought to send the values's ASCII rappresentation using ITOA with this code:
void ShowRegisters(byte rFrom, byte rEnd) {
byte tst[] = { 5, 200, 100, 30, 40, 60, 70, 80, 99 }; //test array for the example
char arr[37]; // enough for 3x9 (values) +9 (commas) chars + terminator
byte pos;
for (uint8_t i = rFrom; i < rEnd + 1; i++) {
// itoa(AS3935_Read(i),&arr[pos++],10);
itoa(tst[i], &arr[pos++], 10);
if (i < 8) {
arr[pos++] = ',';
} else {
arr[pos] = '\0';
}
}
esp_now_send(broadcastAddress, (uint8_t *)&arr, ++pos);
}
This is almost working; if values are all <10 it is ok, otherwise, as in the above example, I receive:
5,2,1,3,4,6,7,8,9
so just the first digit; I'm quite sure there is stupid mistake somewhere, but where?
Thanks