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:
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
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
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.
device_id
, which may prohibit per-device querying in the TTN Data Storage integration.
See a knowledge base article: https://od.decentlab.com/knowledge/article/149
See a knowledge base article: https://od.decentlab.com/knowledge/article/58
See a knowledge base article: https://od.decentlab.com/knowledge/article/40
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.
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.
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.