Ok, so I tried this code for sender:
void loop()
{
if(lora_idle == true)
{
delay(1000);
txNumber += 0.01;
sprintf(txpacket,"%d",12); //start a package
float celsius = 12.19;
//float pressure = 998.76 / 100.0F;
//pressure * 100;
float pressure = 97.32;
float humaidity = 67.24;
//translate float value to int 16 bit *100 get rid of the .
int16_t temperature = (int16_t)(celsius * 100);
int16_t barometer = (int16_t) (pressure *100) ;
//serialMonitor.println(barometer);
int16_t humidity = (int16_t)(humaidity * 100);
byte data[6];
data[0] = temperature >> 8;
data[1] = temperature & 0xFF;
data[2] = highByte(barometer);
data[3] = lowByte(barometer);
data[4] = humidity >> 8;
data[5] = humidity & 0xFF;
Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",data, sizeof(data));
Radio.Send( (uint8_t *)data, sizeof(data) ); //send the package out
lora_idle = false;
}
Radio.IrqProcess( );
}
and this for receiver:
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
rssi=rssi;
rxSize=size;
memcpy(rxpacket, payload, size );
rxpacket[size]='\0';
Radio.Sleep( );
Serial.printf("\r\nreceived packet \"%s\" with rssi %d , length %d\r\n",rxpacket,rssi,rxSize);
lora_idle = true;
int myVal1 = ((int)(payload[0]) << 8) + payload[1];
int myVal2 = ((int)(payload[2]) << 8) + payload[3];
Serial.println("");
Serial.println(myVal1);
Serial.println(myVal2);
}
This seems to be working - I get these values on the serial monitor:
The functions highByte() and lowByte() on the senderâs side are useful, but splitting the payload to individual values on the receiverâs side is annoying.
Arenât there any functions for ESP32 that can automatically decode the payload if I know that, for example, each value is a decimal number of length 2 bytes?
Thank you