Approaches for Effcient Payload Encoding

Just in case you didn’t know: TTN supports ConCaVa-like “payload functions”, which can even give one very readable JSON output directly in the MQTT messages.

See “Decode the Payload in the Console” in The Things Uno Workshop, to get from, for example:

03 0B 07 BE

…to:

{
  "celcius": 19.82,
  "light": 779
}

…by simply defining the following for your application’s decoder function:

function Decoder(bytes, port) {
  var light = bytes[0]<<8 | bytes[1];
  // Sign-extend to 32 bits to support negative values, by shifting 24 bits 
  // (too far) to the left, followed by a sign-propagating right shift:
  var temperature = bytes[2]<<24>>16 | bytes[3];  
  return {
    light: light,
    celcius: temperature / 100
  };
}

(And see also Best practices to limit application payloads.)