Make a TTN v2 payload decoder work with TTI/N v3
function Decoder(bytes, port) { | |
// Your "old" TTN v2 decoder function | |
return bytes; | |
} | |
// add other functions (Converter, Validator) here if you used them. If you didn't you can just skip them. | |
function decodeUplink(input) { | |
var data = input.bytes; | |
var valid = true; | |
if (typeof Decoder === "function") { | |
data = Decoder(data, input.fPort); | |
} | |
if (typeof Converter === "function") { | |
data = Converter(data, input.fPort); | |
} | |
if (typeof Validator === "function") { | |
valid = Validator(data, input.fPort); | |
} | |
if (valid) { | |
return { | |
data: data | |
}; | |
} else { | |
return { | |
data: {}, | |
errors: ["Invalid data received"] | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment