Hi! I’ve recently made a PR that simplifies a little the decoded payload, but the structure that Seeed is using in these devices is still annoying.
Ideally, we will just add a normalizeUplink
function to achieve this (Uplink | The Things Stack for LoRaWAN), think of it as an extra/optional step that takes the output of the decodeUplink
function and beautifies/standardizes it. But the normalized payload format is still young and does not yet support the UV Index and Rain Gauge fields provided by this device. Anyway, if you don’t want to touch the original decodeUplink
function and don’t mind losing the unsupported fields, adding this function will be a solution:
// Be aware of corner cases
function normalizeUplink(input) {
var data = { air: {}, wind: {} };
for (var i = 0; i < input.data.messages.length; i++) {
var msg = input.data.messages[i];
switch (msg.measurementId) {
case "4097":
data.air.temperature = msg.measurementValue;
break;
case "4098":
data.air.relativeHumidity = msg.measurementValue;
break;
case "4099":
data.air.lightIntensity = msg.measurementValue;
break;
case "4101":
data.air.pressure = msg.measurementValue / 100; // convert to hPa
break;
case "4104":
data.wind.direction = msg.measurementValue;
break;
case "4105":
data.wind.speed = msg.measurementValue;
break;
default:
break;
}
}
return {data};
}
That code will produce something like this:
{
"air": {
"temperature": 7.2,
"relativeHumidity": 59,
"lightIntensity": 435,
"pressure": 89080
},
"wind": {
"speed": 1.1,
"direction": 277
}
}
Sadly, this won’t work for you just yet, while these fields are supported in the schema, air.lightIntensity
hasn’t yet been added to the validation code of The Things Stack. I have a patched version running locally and this works fine, I will try to prepare a PR as soon as possible so that everyone can use these fields in the normalized format. For now, you can just remove the lightIntensity
case from the switch statement.
I will let you know with updates on using this approach.
I don’t like the hacky approach of patching the original decodeUplink
function, so I’m willing to take the long route here of making a useful and easy to use format for all.