I'm having a problem with the decoder I'm using. Using my ESP32 I'm encoding my value with the following code:
float Energia;
int sensorValue = Energia *100;
Serial.println("Reading is:" );
Serial.println(sensorValue);
// int -> byte array
byte payload[2];
// Sensor
payload[0] = lowByte(sensorValue);
payload[1] = highByte(sensorValue);
The code I'm using in the decoder in Chirpstack is the following:
function Decode(fPort, bytes, variables) {
var decoded = {};
// Check this is a message with a payload (fPort is not 0, which is used for status messages)
if (fPort !== 0) {
// Calculate the original moisture value from the two-byte payload
decoded.Energia2 = bytes[0] + bytes[1] * 256;
decoded.Energia2 = decoded.Energia2 /100.0;
}
return decoded;
}
This way to encode and decode works fine with small values, but when I try to send a big value, for example 1234567.89 in the variable Energia, the decoder returns a value that doesn't makes sense.
Thanks in advance for any suggestion!