johannesE / decentlab-decoders

Sample payload decoders

Home Page:https://www.decentlab.com/products

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Payload decoders for Decentlab sensor devices

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

Supported platforms are:

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

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

Please browse the devices in the corresponding directories:

Device Name
DL-10HS Legacy Large Soil Moisture Sensor for LoRaWANTM
DL-5TE Legacy Soil Moisture, Temperature and Electrical Conductivity Sensor for LoRaWANTM
DL-5TM Legacy Soil Moisture, Temperature Sensor for LoRaWANTM
DL-AC Air Quality Station NO2, NO, CO, Ox for LoRaWANTM
DL-ATM22 Wind Speed, Wind Direction and Temperature Sensor for LoRaWANTM
DL-ATM41 Eleven Parameter Weather Station for LoRaWANTM
DL-CTD10 Pressure / Liquid Level, Temperature and Electrical Conductivity Sensor for LoRaWANTM
DL-DLR2-004 Analog 4 … 20mA sensor for LoRaWANTM
DL-DS18 Temperature Sensor for LoRaWANTM
DL-GS3 Legacy Ruggedized Soil Moisture, Temperature and Electrical Conductivity Sensor for LoRaWANTM
DL-IAM Indoor Ambiance Monitor for LoRaWANTM
DL-ITST Infrared Thermometer / Surface Temperature Sensor for LoRaWANTM
DL-KL66 Strain / Weight Sensor for LoRaWANTM
DL-LP8P CO2, Temperature, Humidity and Barometric Pressure Sensor for LoRaWANTM
DL-MBX Ultrasonic Distance / Level Sensor for LoRaWANTM
DL-PAR Photosynthetically Active Radiation Sensor for LoRaWANTM
DL-PR21 Pressure / Liquid Level and Temperature Sensor with Pipe Thread for LoRaWANTM
DL-PR26 Pressure / Liquid Level and Temperature Sensor for LoRaWANTM
DL-PR36 High-Precision Pressure / Liquid Level and Temperature Sensor for LoRaWANTM
DL-PR36CTD High-Precision Pressure / Liquid Level, Temperature and Electrical Conductivity Sensor for LoRaWANTM
DL-PYR Total Solar Radiation Sensor for LoRaWANTM
DL-SHT21 Air Temperature and Humidity Sensor with Radiation Shield for LoRaWANTM
DL-SHT35 Air Temperature and Humidity Sensor with Radiation Shield for LoRaWANTM
DL-SMTP Soil Moisture and Temperature Profile for LoRaWANTM
DL-TBRG Tipping Bucket Rain Gauge for LoRaWANTM
DL-TRS11 Soil Moisture and Temperature Sensor for LoRaWANTM
DL-TRS12 Soil Moisture, Temperature and Electrical Conductivity Sensor for LoRaWANTM
DL-TRS21 Soil Water Potential and Temperature Sensor for LoRaWANTM
DL-ZN11O Dendrometer for LoRaWANTM

Integration guide for some platforms

The Things Network

Go to your application on TTN Console and select Payload Formats. Take the JavaScript implementation and paste into the decoder window by overwriting its content. Remove the main() function and its call.

function main() {
    ...
}

main();

Append the following lines.

function Decoder(bytes, port) {
  return decentlab_decoder.decode(bytes);
}

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

ELEMENT IoT

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

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()

Replace the spaces in the field names with _. For example:

  ...
   ["values"] = {
     {["name"] = "Battery voltage",
      ["convert"] = function (x) return x[0 + 1] / 1000 end,
      ["unit"] = "V"}
  ...

becomes

  ...
   ["values"] = {
     {["name"] = "Battery_voltage",
      ["convert"] = function (x) return x[0 + 1] / 1000 end,
      ["unit"] = "V"}
  ...

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 by clicking Run and make sure the output values match against the datasheet. Configure the fields in Node fields accordingly and press Save icon.

About

Sample payload decoders

https://www.decentlab.com/products

License:MIT License


Languages

Language:Elixir 20.7%Language:PHP 15.9%Language:C# 15.2%Language:Erlang 14.2%Language:Lua 12.0%Language:Python 11.2%Language:JavaScript 10.8%