Customer Decoder Functions

Custom decoders are decoder functions that you can write yourself. This gives you the flexibility to decode LoRaWAN uplink messages that contain a specific set of fields. You can use custom decoders to decode messages that are sent by different devices or to decode messages that contain a specific set of data.

Examples

The following example will generate an output object containing decoded values for STATUS, BATTERY, and COUNT.

example.js
function decoder(input){
    var bytes = input.bytes;
    var fPort = input.fPort;
    
    var output = {
        STATUS: bytes[0] & 0x01,
        BATTERY: (25 + (bytes[1] & 0x0f)) / 10,
        COUNT: (bytes[7] << 16) | (bytes[6] << 8) | bytes[5],
    };
    return output;
}

Output:

example.js
{
  "STATUS": 0,
  "BATTERY": 2.5,
  "COUNT": 0
}

The following example will directly return the same object with decoded values for STATUS, BATTERY, and COUNT.

example.js
function decoder(input){
    var bytes = input.bytes;
    var fPort = input.fPort;
    
    return {
        STATUS: bytes[0] & 0x01,
        BATTERY: (25 + (bytes[1] & 0x0f)) / 10,
        COUNT: (bytes[7] << 16) | (bytes[6] << 8) | bytes[5],
    };
}

Output:

example.js
{
  "STATUS": 0,
  "BATTERY": 2.5,
  "COUNT": 0
}

The following example will return the same object with decoded values for STATUS, BATTERY, COUNT combined with SNR and RSSI values:

function decoder(input){
    var bytes = input.bytes;
    var fPort = input.fPort;
    var metadata = input.metadata;
    var snr, rssi;
 
    if(metadata && metadata.gws && metadata.gws.length > 0){
        snr = metadata.gws[0].snr;
        rssi = metadata.gws[0].rssi;
    }
 
    return {
        STATUS: bytes[0] & 0x01,
        BATTERY: (25 + (bytes[1] & 0x0f)) / 10,
        COUNT: (bytes[7] << 16) | (bytes[6] << 8) | bytes[5],
        SNR: snr,
        RSSI: rssi
    };
}

Output:

{
    "STATUS": 171,
    "BATTERY": 2.7,
    "COUNT": 14348907,
    "SNR": 8.7,
    "RSSI": -40
}

The example metadata used for the example:

{
  "cmd": "gw",
  "seqno": 12345,
  "EUI": "ABCD1234567890EF",
  "ts": 1111111111111,
  "fcnt": 6789,
  "port": 2,
  "freq": 123456789,
  "toa": 21,
  "dr": "SF8 BW125 4/5",
  "ack": true,
  "gws": [
    {
      "rssi": -40,
      "snr": 8.7,
      "ts": 1111111111111,
      "time": "2023-08-16T10:33:53.433Z",
      "gweui": "1111222233334444",
      "ant": 1,
      "lat": 45.123456,
      "lon": -1.234567
    }
  ],
  "bat": 150,
  "data": "abcdef1234567890"
}

logo

Start building today

Collect, process, and activate device data. Scale from one device to thousands.

Qubitro Logo

Product

Decision Aids

Resources

Company

© 2024 Qubitro, Inc. All rights reserved