Last active
March 22, 2024 06:29
-
-
Save tiefpunkt/9407f4049365c065fdd6905adf949993 to your computer and use it in GitHub Desktop.
Make a TTN v2 payload decoder work with TTI/N v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Decoder(bytes, port) { | |
// Your "old" TTN v2 decoder function | |
} | |
// 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
You need to return the
decoded
object, and then they will be. I see where you might be coming from. If you use the following Decoder function you should get what you're aiming for: