I am attempting to convert my v2 payload formatter to v3 without any success. One point at the moment is retrieving the fport.
My v2 payload formatter commenced:
function Decoder(bytes, fport) {
var decoded = {};
if (fport === 6) {
Following documentation at *1 and a Decode Uplink Example from *2 I have converted this to a v3 payload formatter commencing:
function decodeUplink(input) {
var bytes = input.bytes;
var decoded = {};
var fport = input.fPort;
if (fport === 6) {
This is not functioning (my webHooks endpoint receives an empty decoded payload). So, I have tried using the device “Payload formatters” tab to test some payload formatters. There I have tried augmenting the default code below to include “input.fPort” like this:
function decodeUplink(input) {
return {
data: {
bytes: input.bytes,
fport: input.fPort
},
warnings: [],
errors: []
};
}
Pasting in an actual payload from one of my devices of “AQMBJAhyACUBAAA=” this resturns an fport value of 1:
{
"bytes": [
0,
0,
170,
0
],
"fport": 1
}
yet when I look at the JSON “Event details” in the console “Live data” for the device it clearly states f_port is 6, and 6 correlates to what I would expect:
"uplink_message": {
"session_key_id": "XXXX",
"f_port": 6,
"f_cnt": 293,
"frm_payload": "AQMBJAh8AB8AAAA=",
"decoded_payload": {
I suspected that given the JSON refers to it as “f_port” perhaps I should be using “Input.f_port” but that is not fruitful.
Can anyone shed light on this please.
Thanks,
Roger.
References:
*1: Migrating End Devices from V2 | The Things Stack for LoRaWAN
*2: Javascript | The Things Stack for LoRaWAN