Thanks for all your replies and your patience with a newbie like me
Good point about the decimals, a second decimal should not be needed, I would like to have 1 decimal precision however.
What https://www.h-schmidt.net/FloatConverter/IEEE754.html is doing is exactly what I would like to do in my payload function. I still can’t figure out how my payload function should look to do the same thing.
This is by the way my Arduino code, which largely is the same as the sample on https://github.com/jpmeijers/RN2483-Arduino-Library
In this code I’m still using 4 bytes.
#include <rn2xx3.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include "i2c.h"
#include "i2c_SI7021.h"
SI7021 si7021;
SoftwareSerial mySerial(10, 11); // RX, TX
//create an instance of the rn2xx3 library,
//giving the software serial as port to use
rn2xx3 myLora(mySerial);
// the setup routine runs once when you press reset:
void setup()
{
Serial.begin(57600); //serial port to computer
si7021.initialize();
//output LED pin
pinMode(13, OUTPUT);
led_on();
// Open serial communications and wait for port to open:
mySerial.begin(9600); //serial port to radio
Serial.println("Startup");
initialize_radio();
led_off();
delay(2000);
}
void initialize_radio()
{
//reset rn2483
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
delay(500);
digitalWrite(12, HIGH);
delay(100); //wait for the RN2xx3's startup message
mySerial.flush();
//Autobaud the rn2483 module to 9600. The default would otherwise be 57600.
myLora.autobaud();
//check communication with radio
String hweui = myLora.hweui();
while(hweui.length() != 16)
{
Serial.println("Communication with RN2xx3 unsuccesful. Power cycle the board.");
Serial.println(hweui);
delay(10000);
hweui = myLora.hweui();
}
//print out the HWEUI so that we can register it via ttnctl
Serial.println("When using OTAA, register this DevEUI: ");
Serial.println(myLora.hweui());
Serial.println("RN2xx3 firmware version:");
Serial.println(myLora.sysver());
//configure your keys and join the network
Serial.println("Trying to join TTN");
bool join_result = false;
//ABP: initABP(String addr, String AppSKey, String NwkSKey);
join_result = myLora.initABP("02017201", "8D7FFEF938589D95AAD928C2E2E7E48F", "AE17E567AECC8787F749A62F5541D522");
while(!join_result)
{
Serial.println("Unable to join. Are your keys correct, and do you have TTN coverage?");
delay(60000); //delay a minute before retry
join_result = myLora.init();
}
Serial.println("Successfully joined TTN");
}
// the loop routine runs over and over again forever:
void loop()
{
led_on();
static float temp;
si7021.getTemperature(temp);
si7021.triggerMeasurement();
Serial.print("TXing: ");
Serial.println(String(temp));
typedef union
{
float number;
uint8_t bytes[4];
} FLOATUNION_t;
FLOATUNION_t myFloat;
myFloat.number = temp;
myLora.txBytes(myFloat.bytes, sizeof(myFloat.bytes));
led_off();
//wait 5 minutes
delay(300000);
}
void led_on()
{
digitalWrite(13, 1);
}
void led_off()
{
digitalWrite(13, 0);
}