I need to send data to The Things Network and the data need to in bytes
To send data back and forth over The Things Network you’ll need to use bytes
Some functions return a float with 2 decimal
23.56 or 4.32
I have big difficulties to convert my float and save it to a varaible uint8_t my data. I have to find how to convert my float variable
I have a loop like this:
/*
NOTE:
uinit8_t mydata[64];
byte nbMaxCapteurs = 10;
mesMesures[i][mesCapteur[i].idDuCapteur].valeur => this is a float
*/
memset(mydata, 0xFF, 64);
uint8_t * ptr = mydata;
for (byte i = 0; i < nbMaxCapteurs; i++) {
if (mesCapteur[i].actif) {
*ptr = mesMesures[i][mesCapteur[i].idDuCapteur].valeur;
ptr += 15; // How to know the number of step to move the pointer
if (i < nbCapteurActif + 1) {
*ptr = 0x2C; // virgule
ptr += sizeof(char);
}
} else {
*ptr = 0x2C; // virgule pour les capteurs inactifs
ptr += sizeof(char);
}
}
*ptr = '00'; // Close \0
ptr += sizeof(char);
printData();
I am very new to such conversions. The real problem is here:
*ptr = mesMesures[i][mesCapteur[i].idDuCapteur].valeur;
printData prints this:
04 FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C 18 FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C CB FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C A8 FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C
But it should print at least this:
34 2E 33 32 FF FF FF FF FF FF FF FF FF FF FF 2C 18 FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C CB FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C A8 FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C
Because 34 2e 33 32
is equals to 4.32.
I don't understand and don't know how I can "merge" and convert a float value. And then could you help me move the pointer following the size of the float?
I'm really stuck with that topic and I would really appreciate your help.