Things Stack Javascript Parser


Hardware providers often provide parsers for their LoRaWAN devices for the LoRaWAN network server ‘Things Stack’, for example via the Things Stack Device Repository or via the provider’s own repositories.

These parsers can be used in niotix as Javascript function parsers by adding a wrapper that adapts the parser to the niotix format, depending on the format.

In the Things Stack V3 format, the LoRaWAN payload is passed as a hex bytes array (bytes), together with the frame port (fport) in one object. The name of the decoder function is decodeUplink. The exact format is described in the provider’s Things Stack documentation.

Example wrapper for using a Things Stack V3 decoder as a Javascript function parser:

module.exports = (payload, meta) => {
  const fPort = meta.lora.fport;
  const bytes = hexToBytes(payload);

  return decodeUplink({
    fPort,
    bytes,
  });
};

function hexToBytes(hex) {
  const hexBuffer = Buffer.from(hex, "hex");
  return Array.from(hexBuffer);
}

In the Things Stack V2 format, the LoRaWAN payload is transferred as a hex buffer and the frame port as a separate parameter. The name of the decoder function is Decoder. This format is generally only found in older decoders.

Example wrapper for using a Things Stack V2 decoder as a Javascript function parser:

module.exports = function (payload, meta) {
  const port = meta.lora.fport;
  const buf = Buffer.from(payload, 'hex');
  return Decoder(buf, port); 
}