diff --git a/milesight-iot-em400-tld/CHANGELOG.md b/milesight-iot-em400-tld/CHANGELOG.md new file mode 100644 index 000000000..57140b7b5 --- /dev/null +++ b/milesight-iot-em400-tld/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.0.0 - 2026-04-16 + +- First version of plugin \ No newline at end of file diff --git a/milesight-iot-em400-tld/LICENSE.md b/milesight-iot-em400-tld/LICENSE.md new file mode 100644 index 000000000..bffeef341 --- /dev/null +++ b/milesight-iot-em400-tld/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2026 Thinger.io + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/milesight-iot-em400-tld/README.md b/milesight-iot-em400-tld/README.md new file mode 100644 index 000000000..3a0d5bdd5 --- /dev/null +++ b/milesight-iot-em400-tld/README.md @@ -0,0 +1,86 @@ +# EM400-TLD - ToF Laser Distance Sensor + +The EM400-TLD is a distance sensor based on ToF (Time of Flight) technology, designed for detecting fill level and position status. With a detection range of 2 to 350 cm and minimal blind zone, it is particularly suitable for monitoring waste bins, containers, and various distance measurement applications. The device features dual 9000 mAh replaceable batteries providing up to 10 years of operation, IP67 protection rating, and NFC configuration capabilities. + +## Thinger.io Integration + +## Requirements + +A LoRaWAN server is required to communicate the Milesight EM400-TLD into Thinger.io, some options are: + +- [The Things Stack](https://www.thethingsindustries.com/stack/) +- [LORIOT](https://loriot.io/) +- [ChirpStack](https://www.chirpstack.io/) + +Alongside, the corresponding plugin for the selected LoRaWAN server needs to be installed in your Thinger.io instance. + +## Get Started + +### Installation + +Look for the plugin in the [Thinger.io Plugin Store](https://marketplace.thinger.io/) and install it in your Thinger.io instance. Once the plugin is installed a new Product will be created for this device. + +### Configuration + +The Product is already preconfigured, check that the auto provision prefix matches the one selected in your LoRaWAN server plugin in Thinger.io, or change it to your desire. + +### Usage + +Start sending uplinks for autoprovisioning devices and buckets. +This product also provides a predefined dashboard and downlinks. + +## Features + +- **ToF Distance Measurement**: 2-350 cm detection range with 27° field of view +- **High Accuracy**: ±2 cm detection accuracy across -20°C to 70°C +- **Temperature Monitoring**: Built-in sensor with -40°C to 125°C range +- **Position Detection**: Normal/Tilt status monitoring with accelerometer +- **Long Battery Life**: Dual 9000 mAh replaceable batteries, up to 10 years operation +- **NFC Configuration**: One-touch configuration and card emulation mode +- **LoRaWAN Connectivity**: Class A, OTAA/ABP modes +- **Wide Frequency Support**: CN470/IN865/RU864/EU868/US915/AU915/KR920/AS923 +- **Rugged Design**: IP67 rated, ABS + PC housing +- **Operating Modes**: Standard mode and Bin mode +- **Advanced Features**: Threshold alarms, cumulative reporting, tilt & distance switch + +## Technical Specifications + +| Parameter | Specification | +|-----------|---------------| +| **Detection Range** | 2 - 350 cm | +| **Detection Accuracy** | ±2 cm (-20°C ~ 70°C) | +| **Detection Resolution** | 1 mm | +| **Field of View** | 27° | +| **Temperature Range** | -40°C ~ 125°C | +| **Temperature Resolution** | 0.1°C | +| **LoRaWAN Frequency** | CN470/IN865/RU864/EU868/US915/AU915/KR920/AS923-1&2&3&4 | +| **Tx Power** | 16 dBm (868 MHz) / 20 dBm (915 MHz) / 19 dBm (470 MHz) | +| **Sensitivity** | -137 dBm @300 bps | +| **Class** | A | +| **Activation** | OTAA/ABP | +| **Power Supply** | 2 × 9000 mAh ER26500 Li-SOCL2 Batteries | +| **Battery Life** | Up to 10 years (standard mode: 10 min interval, 25°C) | +| **Operating Temperature** | -30°C ~ 70°C | +| **Humidity** | ≤95% (non-condensing) | +| **Ingress Protection** | IP67 | +| **Dimensions** | 118 × 65 × 30 mm | +| **Weight** | 208.3 g | +| **Housing Material** | ABS + PC (UL94 V0) | + +## Use Cases + +- Waste bin fill level monitoring +- Container level detection +- Parking space occupancy detection +- Position and tilt status monitoring +- Distance measurement applications +- Smart city waste management +- Industrial level monitoring + +## Additional Resources + +Milesight resources can be found at: + +- [Datasheet](https://resource.milesight.com/milesight/iot/document/em400-tld-datasheet-en.pdf) +- [User Guide](https://resource.milesight.com/milesight/iot/document/em400-tld-user-guide-en.pdf) +- [Thinger docs](https://docs.thinger.io) \ No newline at end of file diff --git a/milesight-iot-em400-tld/assets/em400-tld.png b/milesight-iot-em400-tld/assets/em400-tld.png new file mode 100644 index 000000000..10f606418 Binary files /dev/null and b/milesight-iot-em400-tld/assets/em400-tld.png differ diff --git a/milesight-iot-em400-tld/plugin.json b/milesight-iot-em400-tld/plugin.json new file mode 100644 index 000000000..ce5581b4a --- /dev/null +++ b/milesight-iot-em400-tld/plugin.json @@ -0,0 +1,422 @@ +{ + "name": "milesight_iot_em400_tld", + "version": "1.0.0", + "description": "EM400-TLD is a distance sensor based on ToF (timeof flight), whichis mainly used for detecting the fill level and positionstatus.", + "author": "Thinger.io", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/thinger-io/plugins.git", + "directory": "milesight-iot-em400-tld" + }, + "metadata": { + "name": "Milesight-Iot EM400-TLD", + "description": "EM400-TLD is a distance sensor based on ToF (timeof flight), whichis mainly used for detecting the fill level and positionstatus.", + "image": "assets/em400-tld.png", + "category": "devices", + "vendor": "milesight-iot" + }, + "resources": { + "products": [ + { + "description": "EM400-TLD is a distance sensor based on ToF (timeof flight), whichis mainly used for detecting the fill level and positionstatus.", + "enabled": true, + "name": "Milesight-Iot EM400-TLD", + "product": "milesight_iot_em400_tld", + "profile": { + "api": { + "downlink": { + "enabled": true, + "handle_connectivity": false, + "request": { + "data": { + "path": "/downlink", + "payload": "{\n \"data\" : \"{{payload.data=\"\"}}\",\n \"port\" : {{payload.port=2}},\n \"priority\": {{payload.priority=3}},\n \"confirmed\" : {{payload.confirmed=false}},\n \"uplink\" : {{property.uplink}} \n}", + "payload_function": "", + "payload_type": "", + "plugin": "{{property.uplink.source}}", + "target": "plugin_endpoint" + } + }, + "response": { + "data": { + "source": "request_response" + } + } + }, + "uplink": { + "enabled": true, + "handle_connectivity": true, + "request": { + "data": { + "payload": "{{payload}}", + "payload_function": "", + "payload_type": "source_payload", + "resource_stream": "uplink", + "target": "resource_stream" + } + }, + "response": { + "data": { + "source": "request_response" + } + } + } + }, + "autoprovisions": { + "device_autoprovisioning": { + "config": { + "mode": "pattern", + "pattern": "em400_tld_.*" + }, + "enabled": true + } + }, + "buckets": { + "milesight_em400_tld_data": { + "backend": "mongodb", + "data": { + "payload": "{{payload}}", + "payload_function": "", + "payload_type": "source_payload", + "resource_stream": "uplink_decoded", + "source": "resource_stream" + }, + "enabled": true, + "retention": { + "period": 3, + "unit": "months" + }, + "tags": [] + } + }, + "code": { + "code": "function decodeThingerUplink(thingerData) {\n // 0. If data has already been decoded, we will return it\n if (thingerData.decodedPayload) return thingerData.decodedPayload;\n \n // 1. Extract and Validate Input\n // We need 'payload' (hex string) and 'fPort' (integer)\n const hexPayload = thingerData.payload || \"\";\n const port = thingerData.fPort || 1;\n\n // 2. Convert Hex String to Byte Array\n const bytes = [];\n for (let i = 0; i < hexPayload.length; i += 2) {\n bytes.push(parseInt(hexPayload.substr(i, 2), 16));\n }\n\n // 3. Dynamic Function Detection and Execution\n \n // CASE A: (The Things Stack v3)\n if (typeof decodeUplink === 'function') {\n try {\n const input = {\n bytes: bytes,\n fPort: port\n };\n var result = decodeUplink(input);\n \n if (result.data) return result.data;\n\n return result; \n } catch (e) {\n console.error(\"Error inside decodeUplink:\", e);\n throw e;\n }\n }\n\n // CASE B: Legacy TTN (v2)\n else if (typeof Decoder === 'function') {\n try {\n return Decoder(bytes, port);\n } catch (e) {\n console.error(\"Error inside Decoder:\", e);\n throw e;\n }\n }\n\n // CASE C: No decoder found\n else {\n throw new Error(\"No compatible TTN decoder function (decodeUplink or Decoder) found in scope.\");\n }\n}\n\n\n// TTN decoder\nfunction decodeUplink(input) {\n var res = Decoder(input.bytes, input.fPort);\n if (res.error) {\n return {\n errors: [res.error],\n };\n }\n return {\n data: res,\n };\n}\n/**\n * Payload Decoder for The Things Network\n *\n * Copyright 2023 Milesight IoT\n *\n * @product EM400-TLD\n */\nfunction Decoder(bytes, port) {\n return milesight(bytes);\n}\n\nfunction milesight(bytes) {\n var decoded = {};\n\n for (var i = 0; i < bytes.length; ) {\n var channel_id = bytes[i++];\n var channel_type = bytes[i++];\n // BATTERY\n if (channel_id === 0x01 && channel_type === 0x75) {\n decoded.battery = bytes[i];\n i += 1;\n }\n // TEMPERATURE\n else if (channel_id === 0x03 && channel_type === 0x67) {\n decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;\n i += 2;\n }\n // DISTANCE\n else if (channel_id === 0x04 && channel_type === 0x82) {\n decoded.distance = readUInt16LE(bytes.slice(i, i + 2));\n i += 2;\n }\n // POSITION\n else if (channel_id === 0x05 && channel_type === 0x00) {\n decoded.position = bytes[i] === 0 ? \"normal\" : \"tilt\";\n i += 1;\n }\n // TEMPERATURE WITH ABNORMAL\n else if (channel_id === 0x83 && channel_type === 0x67) {\n decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;\n decoded.temperature_abnormal = bytes[i + 2] == 0 ? false : true;\n i += 3;\n }\n // DISTANCE WITH ALARMING\n else if (channel_id === 0x84 && channel_type === 0x82) {\n decoded.distance = readUInt16LE(bytes.slice(i, i + 2));\n decoded.distance_alarming = bytes[i + 2] == 0 ? false : true;\n i += 3;\n } else {\n break;\n }\n }\n\n return decoded;\n}\n\n/* ******************************************\n * bytes to number\n ********************************************/\nfunction readUInt16LE(bytes) {\n var value = (bytes[1] << 8) + bytes[0];\n return value & 0xffff;\n}\n\nfunction readInt16LE(bytes) {\n var ref = readUInt16LE(bytes);\n return ref > 0x7fff ? ref - 0x10000 : ref;\n}\n", + "environment": "javascript", + "storage": "", + "version": "1.0" + }, + "flows": { + "milesight_em400_tld_decoder": { + "data": { + "payload": "{{payload}}", + "payload_function": "decodeThingerUplink", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "enabled": true, + "sink": { + "payload": "{{payload}}", + "payload_function": "", + "payload_type": "source_payload", + "resource_stream": "uplink_decoded", + "target": "resource_stream" + }, + "split_data": false + } + }, + "properties": { + "uplink": { + "data": { + "payload": "{{payload}}", + "payload_function": "", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "default": { + "source": "value" + }, + "enabled": true + } + } + }, + "_resources": { + "properties": [ + { + "property": "dashboard", + "value": { + "tabs": [ + { + "name": "Overview", + "widgets": [ + { + "layout": { + "col": 0, + "row": 0, + "sizeX": 2, + "sizeY": 5 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Distance" + }, + "properties": { + "decimalPlaces": 0, + "enableExtraTextColor": false, + "enableIconColor": false, + "enableIconSize": false, + "extraText": "", + "extraTextColor": "#1E313E", + "extraTextColorConditions": [], + "extraTextConditions": [], + "extraTextPosition": "above-value", + "extraTextSize": "20px", + "extraTextWeight": "font-light", + "icon": "", + "iconColor": "#1E313E", + "iconColorConditions": [], + "iconConditions": [], + "iconGap": "8px", + "iconPosition": "before-value", + "iconSize": "75px", + "iconVerticalOffset": "0px", + "link": "", + "textAlign": "center", + "textColor": "#1E313E", + "textColorConditions": [], + "textSize": "75px", + "textWeight": "font-light", + "unit": "mm", + "unitSize": "20px" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "milesight_em400_tld_data", + "mapping": "distance", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#1abc9c", + "name": "Source 1", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "text" + }, + { + "layout": { + "col": 0, + "row": 5, + "sizeX": 2, + "sizeY": 5 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Temperature" + }, + "properties": { + "decimalPlaces": 1, + "enableExtraTextColor": false, + "enableIconColor": false, + "enableIconSize": false, + "extraText": "", + "extraTextColor": "#1E313E", + "extraTextColorConditions": [], + "extraTextConditions": [], + "extraTextPosition": "above-value", + "extraTextSize": "20px", + "extraTextWeight": "font-light", + "icon": "", + "iconColor": "#1E313E", + "iconColorConditions": [], + "iconConditions": [], + "iconGap": "8px", + "iconPosition": "before-value", + "iconSize": "75px", + "iconVerticalOffset": "0px", + "link": "", + "textAlign": "center", + "textColor": "#1E313E", + "textColorConditions": [], + "textSize": "75px", + "textWeight": "font-light", + "unit": "ºC", + "unitSize": "20px" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "milesight_em400_tld_data", + "mapping": "temperature", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#1abc9c", + "name": "Source 1", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "text" + }, + { + "layout": { + "col": 2, + "row": 0, + "sizeX": 4, + "sizeY": 10 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Distance (24h)" + }, + "properties": { + "alignTimeSeries": false, + "dataAppend": false, + "options": "var options = {\n chart: {\n type: 'area',\n stacked: false\n },\n dataLabels: {\n enabled: false\n },\n stroke: {\n curve: 'smooth'\n },\n xaxis: {\n type: 'datetime',\n labels: {\n datetimeUTC: false\n },\n tooltip: {\n enabled: false\n }\n },\n yaxis: {\n \"labels\": {\n \"formatter\": function (val) {\n if ( val !== null && typeof val !== 'undefined' )\n return val.toFixed(0) + ' mm';\n }\n }\n },\n tooltip: {\n x: {\n format: 'dd/MM/yyyy HH:mm:ss'\n }\n }\n};\n", + "realTimeUpdate": true + }, + "sources": [ + { + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "milesight_em400_tld_data", + "mapping": "distance", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#3498db", + "name": "Distance", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + } + ], + "type": "apex_charts" + }, + { + "layout": { + "col": 0, + "row": 10, + "sizeX": 2, + "sizeY": 5 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Battery" + }, + "properties": { + "color": "#2ebd59", + "gradient": false, + "max": 100, + "min": 0, + "size": "75px", + "unit": "%" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "milesight_em400_tld_data", + "mapping": "battery", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#1abc9c", + "name": "Source 1", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "gauge" + }, + { + "layout": { + "col": 2, + "row": 10, + "sizeX": 4, + "sizeY": 5 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Temperature (24h)" + }, + "properties": { + "alignTimeSeries": false, + "dataAppend": false, + "options": "var options = {\n chart: {\n type: 'area',\n stacked: false\n },\n dataLabels: {\n enabled: false\n },\n stroke: {\n curve: 'smooth'\n },\n xaxis: {\n type: 'datetime',\n labels: {\n datetimeUTC: false\n },\n tooltip: {\n enabled: false\n }\n },\n yaxis: {\n \"labels\": {\n \"formatter\": function (val) {\n if ( val !== null && typeof val !== 'undefined' )\n return val.toFixed(1) + ' ºC';\n }\n }\n },\n tooltip: {\n x: {\n format: 'dd/MM/yyyy HH:mm:ss'\n }\n }\n};\n", + "realTimeUpdate": true + }, + "sources": [ + { + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "milesight_em400_tld_data", + "mapping": "temperature", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#e74c3c", + "name": "Temperature", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + } + ], + "type": "apex_charts" + } + ] + } + ] + } + } + ] + } + } + ] + } +} \ No newline at end of file