Skip to content

Instantly share code, notes, and snippets.

Last active November 4, 2021 16:10
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Make a TTN v2 payload decoder work with TTI/N v3
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"]
Copy link

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:

function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.
  var decoded = {};
  if (port === 2) decoded.b = bytes[0]/50;
  if (port === 2) = bytes[1]-100;

  return decoded;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment