Hi Everyone,
After having read Decrypting messages for dummies
and played with https://github.com/TheThingsNetwork/workshops/tree/master/The%20Things%20Network
I decided to try on my node sending info from my bme280, so my do_send function look like this
void do_send(osjob_t* j) {
bme.takeForcedMeasurement();
delay(10);
int16_t celciusInt = round(bme.readTemperature() * 100);
int16_t humInt = round(bme.readHumidity() * 100);
int16_t pressInt = (bme.readPressure()/100.0F);
Serial.println(bme.readPressure()/100.0F);
byte payload[6];
payload[0] = highByte(celciusInt);
payload[1] = lowByte(celciusInt);
payload[2] = highByte(humInt);
payload[3] = lowByte(humInt);
payload[4] = highByte(pressInt);
payload[5] = lowByte(pressInt);
if (LMIC.opmode & OP_TXRXPEND) {
} else {
LMIC_setTxData2(1, payload, sizeof(payload), 0);
}
}
And my Decoder function , like this:
function Decoder(bytes, port) {
var decoded = {};
var celciusInt = (bytes[0] << 24 >> 16) | bytes[1];
var humidityInt = (bytes[2] << 24 >> 16) | bytes[3];
var pressureInt = (bytes[4] << 24 >> 16) | bytes[5];
// Decode integer to float
decoded.temperature = celciusInt / 100;
decoded.humidity = humidityInt / 100;
decoded.pressure = pressureInt;
return decoded;
}
But despite that in serial, i got something like 981.45 for example, on the ttn website, i only 981, could anyone help me understand what i did wrong either on the arduino code or on the decoder javascript, either both ^^. I really would like to have 2 decimal precision.
I also tried cayenneLpp library on arduino side and i got only 1 decimal precision, which is not enough for me. (using this javascript decoder https://gist.github.com/iPAS/e24970a91463a4a8177f9806d1ef14b8 )
Thanks a lot
Rgds
Leen