I need some help with the payload of this application. i have managed to get something on the TTN console but i am not sure. The code is the following:
// Output data to serial monitor
Serial.print(“Pressure is : “);
Serial.print(pressure);
Serial.println(” hPa”);
delay(1000);
Wire.end();
On the Serial monitor, I am getting 759,68hPa but i can´t stablish any relation between the payload and the real value. Could anyone help me with this?. I tried everything but I am really stuck with it.
In your Arduino code, you can encode it like this, for example:
int intPressure = pressure / 0.1;
appDataSize = 0;
appData[appDataSize++] = 1; // channel
appData[appDataSize++] = 115; // datatype 115 = barometer
appData[appDataSize++] = (intPressure >> 8) & 0xFF;
appData[appDataSize++] = (intPressure >> 0) & 0xFF;
In the TTN console, you can select Cayenne as the payload format for the application.
When data comes in, it is automatically parsed/decoded from binary to JSON and available in the “payload_fields” field, so you can see it in the console.
They could, but they have three bytes, not the two that Cayenne supports.
@albertogarmendia, when you say the payload, do you mean the payload that you receive. If so, where are you seeing the received payload?
In your code you have separated out the floating point in to three bytes. The payload is usually presented in base64 format which you can convert in to a byte array and then reverse the process back to a float. Except that a float is stored in 4 bytes, so anything could be happening.
We tend to multiply our floats by 10 or 100 or 1000 depending on how many decimal places we have, put it in a long in this case and then split it out in to the four bytes. At the other end the four bytes can be turned back in to a long and divided by the original multiplier.
For a more compact representation, if you know what the absolute minimum & maximum figures could be, you can move the zero point to allow it to fit in to a two byte integer - so if you said 740hPa was the minimum, your 759,68hPa would be x 100 = 75968 - 74000 = 1968. With a base of 740hPa, the maximum would be 740 + 655.36 = 1395.36hPa
Trying to encode a 4-byte Arduino float in three bytes is just not going to work, I think the Arduino code will have to change anyway. So you might as well reconsider the encoding, and choose something relatively “standard” like CayenneLPP.
The original poster could also encode the data read with Wire.read() into 3 bytes, send that over LoRaWAN and Convert pressure data at the backend side.
I have managed to get by adding an extra byte. so now i have the correct number on the TTN. this morning my things network indorro gateway didn´t connect to the LNS. i guess there is some problem with that.