Skip to content

decentlab/decentlab-decoders

Repository files navigation

Payload decoders for Decentlab sensor devices

These samples are provided for integrating Decentlab sensor devices into your system.

Supported platforms/environments are:

  • C#
  • Docksters
  • ELEMENT-IoT Elixir
  • Elixir
  • Erlang
  • Java
  • JavaScript
  • Lua
  • PHP
  • Python

Pull requests fixing issues, improving the quality or supporting new platforms/environments are welcome.

Please browse the devices in the corresponding directories:

Device Name
DL-10HS Legacy Large Soil Moisture Sensor for LoRaWAN®
DL-5TE Legacy Soil Moisture, Temperature and Electrical Conductivity Sensor for LoRaWAN®
DL-5TM Legacy Soil Moisture and Temperature Sensor for LoRaWAN®
DL-AC Air Quality Station NO₂, NO, CO, Oₓ for LoRaWAN®
DL-ALB Albedometer Sensor for LoRaWAN®
DL-ATM22 Wind Speed, Wind Direction and Temperature Sensor for LoRaWAN®
DL-ATM41 Eleven Parameter Weather Station for LoRaWAN®
DL-BLG Black Globe Temperature Sensor for LoRaWAN®
DL-CTD10 Pressure / Liquid Level, Temperature and Electrical Conductivity Sensor for LoRaWAN®
DL-CWS High-Precision Winter Road Maintenance Sensor for LoRaWAN®
DL-DLR2-002 Pulse Counter Dry Contact Transmitter for LoRaWAN®
DL-DLR2-003 Digital Input Dry Contact Transmitter for LoRaWAN®
DL-DLR2-004 Analog 4 … 20 mA Sensor Transmitter for LoRaWAN®
DL-DLR2-005 Analog 0 … 3 V Sensor Transmitter for LoRaWAN®
DL-DLR2-006 Analog Potentiometer Sensor Transmitter for LoRaWAN®
DL-DLR2-008 Analog PT100 Sensor Transmitter for LoRaWAN®
DL-DLR2-009 Analog PT1000 Sensor Transmitter for LoRaWAN®
DL-DLR2-010 Dual Pulse Counter Dry Contact Transmitter for LoRaWAN®
DL-DLR2-011 Dual Digital Input Dry Contact Transmitter for LoRaWAN®
DL-DLR2-012 Analog Strain Gauge Sensor Transmitter for LoRaWAN®
DL-DS18 Temperature Sensor for LoRaWAN®
DL-DWS Weighing Scale for LoRaWAN®
DL-GMM Greenhouse Multi Monitor for LoRaWAN®
DL-GS3 Legacy Ruggedized Soil Moisture, Temperature and Electrical Conductivity Sensor for LoRaWAN®
DL-IAM Indoor Ambiance Monitor including CO₂, TVOC and Motion Sensor for LoRaWAN®
DL-ISF Sapflow Sensor for LoRaWAN®
DL-ITST Infrared Thermometer / Surface Temperature Sensor for LoRaWAN®
DL-KL66 Strain / Weight Sensor for LoRaWAN®
DL-LID Laser Distance / Level Sensor for LoRaWAN®
DL-LP8P CO₂, Temperature, Humidity and Barometric Pressure Sensor for LoRaWAN®
DL-LPW Linear Position / Way for LoRaWAN®
DL-LWS Leaf Wetness Sensor for LoRaWAN®
DL-MBX Ultrasonic Distance / Level Sensor for LoRaWAN®
DL-MES5 Large-Range Optical Turbidity and Temperature Sensor For LoRaWAN®
DL-NTU Optical Turbidity and Temperature Sensor for LoRaWAN®
DL-OPTOD Optical Dissolved Oxygen and Temperature Sensor for LoRaWAN®
DL-PAR Photosynthetically Active Radiation Sensor for LoRaWAN®
DL-PHEHT pH, ORP and Temperature Sensor for LoRaWAN®
DL-PM Particulate Matter, Temperature, Humidity and Barometric Pressure Sensor for LoRaWAN®
DL-PR21 Pressure / Liquid Level and Temperature Sensor with G1/4" Pipe Thread for LoRaWAN®
DL-PR26 Pressure / Liquid Level and Temperature Sensor for LoRaWAN®
DL-PR36 High-Precision Pressure / Liquid Level and Temperature Sensor for LoRaWAN®
DL-PR36CTD High-Precision Pressure / Liquid Level, Temperature and Electrical Conductivity Sensor for LoRaWAN®
DL-PYR Total Solar Radiation Sensor for LoRaWAN®
DL-RHC High-Precision Air Temperature and Humidity Sensor with Radiation Shield for LoRaWAN®
DL-SDD Soil Moisture, Temperature and Salinity Profile For LoRaWAN®
DL-SHT21 Air Temperature and Humidity Sensor with Radiation Shield for LoRaWAN®
DL-SHT35 Air Temperature and Humidity Sensor with Radiation Shield for LoRaWAN®
DL-SMTP Soil Moisture and Temperature Profile for LoRaWAN®
DL-TBRG Tipping Bucket Rain Gauge for LoRaWAN®
DL-TP Temperature Profile for LoRaWAN®
DL-TRS11 Soil Moisture, Temperature and Electrical Conductivity Sensor for LoRaWAN®
DL-TRS12 Soil Moisture, Temperature and Electrical Conductivity Sensor for LoRaWAN®
DL-TRS21 Soil Water Potential and Temperature Sensor for LoRaWAN®
DL-WRM Winter Road Maintenance Sensor for LoRaWAN®
DL-ZN1 Dendrometer for LoRaWAN®
DL-ZN2 Dual Dendrometer for LoRaWAN®

Testing payload

If you need to test a particular payload received from Decentlab devices, please follow this link: https://htmlpreview.github.io/?https://github.com/decentlab/decentlab-decoders/blob/master/payload-test.html

Encoding downlink commands

If you need to encode downlink commands to be sent to Decentlab devices, please follow this link: https://htmlpreview.github.io/?https://github.com/decentlab/decentlab-decoders/blob/master/downlink-command-encoder.html

Integration guide for some platforms

TTNv3

Most Decentlab devices are supported by TTNv3 without the need of manual decoders. See a knowledge base article: https://od.decentlab.com/knowledge/article/50

For the newer devices that are not supported yet, see below.

Go to your device (or application) on TTN Console and select Payload formatters and Uplink. Select Javascript for Formatter type. Take the JavaScript implementation and paste into the Formatter parameter window by overwriting its content. Remove the main() function and its call.

function main() {
    ...
}

main();

Append the following lines.

function decodeUplink(input) {
  var errors = [];
  var data = {};
  var res = decentlab_decoder.decode(input.bytes);
  if ('error' in res) {
    errors = [res['error']]
  } else {
    data = res;
  }
  return {
    data: data,
    warnings: [],
    errors: errors
  };
}

Copy example payload message from the datasheet, paste into Byte payload in Test, and click Test decoder. Make sure the output values match against the datasheet example and save the decoder.

⚠️ The decoders may output nested objects, which are stored as text in the TTN Data Storage integration.

⚠️ The decoders may output a field named device_id, which may prohibit per-device querying in the TTN Data Storage integration.

OrbiWise

See a knowledge base article: https://od.decentlab.com/knowledge/article/149

Helium

See a knowledge base article: https://od.decentlab.com/knowledge/article/58

Chirpstack

See a knowledge base article: https://od.decentlab.com/knowledge/article/40

ELEMENT IoT

Some Decentlab devices are supported by ELEMENT IoT without the need of manual decoders. Please check it before using the manual decoders.

Go to Automation, Parser, and create a new parser. Take ELEMENT-IoT Elixir implementation and paste into the Code window by overwriting its content. Test the provided payloads against the datasheet and save.

ResIOT

Most Decentlab devices are supported by ResIOT without the need of manual decoders.

For the newer devices that are not supported yet, see below.

Go to Nodes/Devices and select the target device. Select Manual Lua Scene from the Payload parsing scene mode list.

Take the Lua implementation and paste into the Lua Code editor. Remove the main() function and its call.

local function main()
  ...
end

main()

Append the following lines.

-- get payload
if resiot_startfrom() == "Manual" then
    payload_hex = payloads[1]
    port = "99"
    deveui = ""
    appeui = ""
else
    payload_hex = resiot_comm_getparam("payload")
    port = resiot_comm_getparam("port")
    deveui = resiot_payload_getparam("deveui")
    appeui = resiot_payload_getparam("appeui")
end

-- decode
local decoded = decentlab_decode(payload_hex)

-- set decoded fields
for k, v in pairs(decoded) do
  if type(v) == "table" then
    if resiot_startfrom() == "Manual" then
      resiot_debug(k .. ": " .. v["value"] .. " " .. (v["unit"] or ""))
    else
      resiot_setnodevalue(appeui, deveui, k, v["value"])
    end
  else
    if resiot_startfrom() == "Manual" then
      resiot_debug(k .. ": " .. v)
    else
      resiot_setnodevalue(appeui, deveui, k, v)
    end
  end
end

Test the decoder by clicking Run and make sure the output values match against the datasheet. Configure the fields in Node fields for each sensor name and press Save icon.

Docksters

Most Decentlab devices are supported by Docksters without the need of manual decoders.

For the newer devices that are not supported yet, see below.

In the Docksters app portal, go to Developer, Device Definitions, and Your Definitions. The JSON-encoded device definitions can be directly uploaded with Upload Device Definition button. However, depending on the use case, you may want to use the following pre-parser to normalize the data format for the device definitions. This pre-parser also determines the device ID from the payload.

function parseProvider(payload, time, encoding) {
    var data = {};
    var buf = Buffer.from(payload, encoding);

    if (buf[0] !== 2) {
        return null;
    }

    data.deviceName = 'DL-' + String((buf[1] << 8) + buf[2]).padStart(5, '0');
    data.payload = buf.toString("hex");
    data.time = time;

    return data;
}

function preParse(payloadStr) {
    // use payloadStr to look up the device name and some other values
    try {
        var obj = JSON.parse(payloadStr);

        if ('applicationID' in obj) {
            return parseProvider(obj.data, obj.time, "base64");
        }

        if ('app_id' in obj) {
            return parseProvider(obj.payload_raw, obj.metadata.time, "base64");
        }

        if ('DevEUI_uplink' in obj) {
            return parseProvider(obj.DevEUI_uplink.payload_hex, obj.DevEUI_uplink.Time, "hex");
        }
    } catch (err) {} //some description of err would be nice

    return null;
}

Once you have a device sending data to Docksters, you will see it in Devices and Pending Devices. Select the matching definition from the list and add it.