Hi all,
I am fiddling around with a LoRa module, in oder to send data to the air I have to convert such a data into HEX format, so far I am having trouble with it, I got a measurement of temperarture which looks like this
float temperature = 27.5;
char data[20];
The function that I can use for sending that data to the LoRa module is this
* @param char* message: char array that will be send
*
* @remarks data is a sequence of digit representing the value of byte stream
* expressed in hexadecimal value (i.e. radio tx 12A435 – the payload
* is composed by the following byte stream: 0x12, 0xA4, 0x35 – 6 digit
* converted in 3 bytes). The maximum length of frame is 510 digit (255 Bytes)
* for LoRa modulation and 128 digit (64 bytes) FSK modulation
uint8_t LoRaWAN::sendRadio(char * message)
So, I have tried quite some functions like dtostrf , dtostrf or strtoul to convert my float into a string and later send it out, so far none of those worked out. The only one which was half working was itoa, in the snippet below, but of course I was missing the value after the dot of the float number
/Converting the temperature into HEX string
itoa (temperature,data,16);//<=Works!
print("Tempererature as HEX ->");
println(data);
print("Data to be send through LoRa ->");
println(data);
// Send packet
error = LoRaWAN.sendRadio( data);
Therefore, I was wondering if you have any suggestions to be able to send my float number into HEX without lossing the decimal value.
Thanks in advance,
REgards!
EDIT: using stroul
dtostrf(temperature,4,2,data);
unsigned long ul = strtoul (data, NULL, 0);
USB.print("Tempererature as HEX ->");
USB.println(ul);
USB.print("Data to be send through LoRa ->");
USB.println(ul);
// Send packet
error = LoRaWAN.sendRadio( (char*)ul);
Shows on serial
Temperature: 27.7500000000
Tempererature as HEX ->27
Data to be send through LoRa ->27
Error waiting for packets. error = 1