Yes, right here:
size_t LoRaClass::write(const uint8_t *buffer, size_t size)
The function wants a pointer to a const uint8_t. If cycleTotal is not a uint8_t, then you must cast its pointer appropriately.
gfvalvo:
Yes, right here:
size_t LoRaClass::write(const uint8_t *buffer, size_t size)
The function wants a pointer to a const uint8_t. If cycleTotal is not a uint8_t, then you must cast its pointer appropriately.
For what reason would/should/could this become a 16 bit instead of a 8 bit variable?
The following example sketch may help to get better meaning of this cryptic code: LoRa.write((const uint8_t*)&cycleTotal, sizeof(cycleTotal));
void setup()
{
Serial.begin(9600);
uint8_t myData[] = {0x41, 0x42, 0x43, 0x44}; //uint8_t could be replaced by byte
//----------------------------------------
uint8_t *ptr; //ptr: a pointer variable; it points the beginning of a byte/uint8_t organized space
ptr = (uint8_t*)&myData; //ptr holds beginning address of a byte (8-bit) organized array
for(int i=0; i<sizeof(myData); i++)
{
Serial.write(*ptr); //get the first byte (8-bit) of the myData[] array pointed by ptr and send
ptr++; //point ot the next byte of the array
}
//--all the above 5 lines of codes could be replaced by the following single line
//Serial.write((uint8_t*)&myData, sizeof(myData));
}
void loop()
{
}
The following example sketch may help to get better meaning of this cryptic code: LoRa.write((const uint8_t*)&cycleTotal, sizeof(cycleTotal));
void setup()
{
Serial.begin(9600);
uint8_t myData = {0x41, 0x42, 0x43, 0x44}; //uint8_t could be replaced by byte
//----------------------------------------
uint8_t ptr;
ptr = (uint8_t)&myData; //ptr holds begining address of a byte (8-bit) organized array
for(int i=0; i<sizeof(myData); i++)
{
Serial.write(ptr); //get the first byte (8-bit) of the myData[] array pointed by ptr and send
ptr++; //point ot the next byte of the array
}
//–all the above 5 lines of codes could be replaced by the following single line //Serial.write((uint8_t)&myData, sizeof(myData));
}
void loop()
{
}
GREAT!!
Thanks for that explainer; pity only once an hour can Karma be added
brice3010:
For what reason would/should/could this become a 16 bit instead of a 8 bit variable?
There is no reason for it to EVER be anything but uint8_t*. That allows a single function to send ANY size data, without having to define multiple functions to handle different sized data. And, uint8_t is ALWAYS an 8-bit value, regardless of what platform you are running on, while int, long, etc. can be different sizes on different processors. On AVR, int is 16-bits, on ARM and ESP int is 32-bits. One AVR, long is 32-bits, while on some other platforms it is 64-bits.
But now that the library has been out there for some time, why change it, when there is really no benefit? Changing it now would break existing code for no good reason.
RayLivingston:
But now that the library has been out there for some time, why change it, when there is really no benefit? Changing it now would break existing code for no good reason.
It wouldn't break anything. A function that specifies a parameter of 'void *' can be called using an argument of ANY pointer type. That's the whole purpose of 'void *'