TTN Payload Decoder for example

Hi
Anybody done a decoder for the example :EndDeviceDemo?
Temp is sent in C and F in ASCII.

Data : 31 39 2E 36 43 2F 36 37 2E 33 46
leads to :
19.6C/67.3F

A solution from Nick gives : TypeError("‘substring’ is not a function") or TypeError("‘substr’ is not a function")


function Decoder(bytes, port) {

var str = '';

for (var n = 0; n < bytes.length; n += 2) {
	str += String.fromCharCode(parseInt(bytes.substring(n, n + 2), 16));
}

return str;

}


Hope you can help.

bytes isn’t a string, it’s a sequence of bytes, so the first byte would be 0x31 which can’t be extracted as two characters. And you have to return an object. Try this:

function Decoder(bytes, port) {

  var decoded = {};

  var str = '';

  for (var n = 0; n < bytes.length; n ++) {
	  str += String.fromCharCode(parseInt(bytes[n]));
  }
  
  decoded.result = str;

  return decoded;
  
}

which yields:

{
  "result": "19.6C/67.3F"
}

Hi Nick

Thank you it works!