Hi everyone,
I’ll start by saying that I’m not expert with LoRa and also with coding, but I’m trying to do something.
I’ve been trying to figure out how to send my encoded data for a few days and then decode it on the server side.
I’m using the RadioLib library.
Didactically, I want to send 2 constant data, that hypothetically represent humidity and temperature (positive integers at the moment).
On the device side, I use this part of code as a teaching example.
uint8_t payload[4];
int16_t tmp;
int16_t hum;
tmp = 0x01; //1 value
tmp = htons(tmp);
memcpy(&payload[0], &tmp, sizeof(tmp));
hum = 0x00 //0 value;
hum = htons(hum);
memcpy(&payload[2], &hum, sizeof(hum));
state = node.uplink(payload, sizeof(payload), 10, false, &eventUp);
LoRa server side I use this below
function decodeUplink(input) {
var float = 0, tmp, hum;
tmp = (input.bytes[0] << 8 | input.bytes[1])/100;
hum = (input.bytes[2] << 8 | input.bytes[3])/100;
return {
date: {
temperatures: tmp,
humidity: hum,
},
warnings: [],
errors: []
};
}
and as output I have this part, as I expect.
"frm_payload": "AAEAAA==",
"decoded_payload": {
"humidity": 0,
"temperatures": 0.01
},
the LoRa server in question is TTN.
I send the same data 10 times, and 10 times I find both frm_payload and hum and temp as expected.
I try to move the exact same decodeUplink code to ChirpStack, but something go wrong.
First of all the payload changes constantly and then the values for hum and temp are also inconsistent.
Where am I wrong? because I’m definitely doing something wrong.
Can anyone help me understand?
note:
- source code from device side is the same;
- I’m using a 4.6 chirpstack installed locally on one my system;
- as gateway, I use a Pi4 with RAK, and for my test I only change network server reference.
thnaks, Davide