diff --git a/milesight-iot-em300-th/CHANGELOG.md b/milesight-iot-em300-th/CHANGELOG.md new file mode 100644 index 000000000..57140b7b5 --- /dev/null +++ b/milesight-iot-em300-th/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-em300-th/LICENSE.md b/milesight-iot-em300-th/LICENSE.md new file mode 100644 index 000000000..bffeef341 --- /dev/null +++ b/milesight-iot-em300-th/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-em300-th/README.md b/milesight-iot-em300-th/README.md new file mode 100644 index 000000000..47a7aa667 --- /dev/null +++ b/milesight-iot-em300-th/README.md @@ -0,0 +1,61 @@ +# EM300-TH - Temperature & Humidity Sensor + +The Milesight LoRaWAN® EM300-TH consists of a temperature and a humidity sensor monitoring indoor and outdoor environments. It is suitable for applications such as greenhouses, cold chains, food prevention, warehouses, residences, offices, and labs. Embedded with a Sensirion high-precision sensor chip, the device offers ultra-wide-distance transmission up to line of sight of 10km and features IP67 UV-resistant and waterproof enclosure. + +## Features + +- High-precision temperature and humidity measurements using Sensirion sensor chip +- LoRaWAN® Class A wireless communication +- IP67 waterproof and UV-resistant enclosure +- Ultra-long battery life up to 10 years with 10-minute reporting interval +- Long-range transmission up to 10 km line of sight +- Compact design (88 x 27 x 87 mm) +- Wide operating temperature range: -30°C to +70°C +- Humidity measurement range: 0% to 100% RH (non-condensing) +- 4000 mAh battery capacity + +## Use Cases + +- Greenhouse environmental monitoring +- Cold chain temperature and humidity tracking +- Food storage and preservation monitoring +- Warehouse climate control +- Office and residential comfort monitoring +- Laboratory environment supervision +- Indoor and outdoor climate monitoring + +## Thinger.io Integration + +The EM300-TH integrates with Thinger.io through LoRaWAN network servers, enabling real-time monitoring and data visualization of temperature and humidity measurements. + +## Requirements + +A LoRaWAN server is required to communicate the Milesight EM300-TH 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. + +## Additional Resources + +Milesight resources can be found at: + +- [EM300-TH Datasheet](https://resource.milesight.com/milesight/iot/document/em300-th-datasheet-en.pdf) +- [EM300 Series User Guide](https://resource.milesight.com/milesight/iot/document/em300-series-user-guide-en.pdf) +- [Thinger docs](https://docs.thinger.io) \ No newline at end of file diff --git a/milesight-iot-em300-th/assets/em300-th.png b/milesight-iot-em300-th/assets/em300-th.png new file mode 100644 index 000000000..300be04b1 Binary files /dev/null and b/milesight-iot-em300-th/assets/em300-th.png differ diff --git a/milesight-iot-em300-th/plugin.json b/milesight-iot-em300-th/plugin.json new file mode 100644 index 000000000..45507e80c --- /dev/null +++ b/milesight-iot-em300-th/plugin.json @@ -0,0 +1,429 @@ +{ + "name": "milesight_iot_em300_th", + "version": "1.0.0", + "author": "Thinger.io", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/thinger-io/plugins.git", + "directory": "milesight-iot-em300-th" + }, + "metadata": { + "name": "Milesight-Iot EM300-TH", + "image": "assets/em300-th.png", + "category": "devices", + "vendor": "milesight-iot" + }, + "resources": { + "products": [ + { + "enabled": true, + "name": "Milesight-Iot EM300-TH", + "product": "milesight_iot_em300_th", + "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" + } + } + }, + "uplink": { + "enabled": true, + "handle_connectivity": true, + "request": { + "data": { + "payload": "{{payload}}", + "payload_function": "", + "payload_type": "source_payload", + "resource_stream": "uplink", + "target": "resource_stream" + } + } + } + }, + "autoprovisions": { + "device_autoprovisioning": { + "config": { + "mode": "pattern", + "pattern": "em300_th_.*" + }, + "enabled": true + } + }, + "buckets": { + "milesight_em300_th_data": { + "backend": "mongodb", + "data": { + "payload": "{{payload}}", + "payload_function": "", + "payload_type": "source_payload", + "resource_stream": "uplink_decoded", + "target": "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\treturn {\n\t data : Decoder(input.bytes, input.fPort),\n\t};\n}\n\nfunction Decoder(bytes, port) {\n var decoded = {};\n\n for (var i = 0; i < bytes.length;) {\n\n var channel_id = bytes[i++];\n\n var channel_type = bytes[i++];\n\n // BATTERY\n\n if (channel_id === 0x01 && channel_type === 0x75) {\n\n decoded.battery = bytes[i];\n\n i += 1;\n\n }\n\n // TEMPERATURE\n\n else if (channel_id === 0x03 && channel_type === 0x67) {\n\n decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;\n\n i += 2;\n\n }\n\n // HUMIDITY\n\n else if (channel_id === 0x04 && channel_type === 0x68) {\n\n decoded.humidity = bytes[i] / 2;\n\n i += 1;\n\n }\n\n\n\n else {\n\n break;\n\n }\n\n }\n\n return decoded;\n\n}\n\nfunction normalizeUplink(input) {\n var data = {};\n var air = {};\n\n if (input.data.temperature) {\n air.temperature = input.data.temperature;\n }\n\n if (input.data.humidity) {\n air.relativeHumidity = input.data.humidity;\n }\n\n if (Object.keys(air).length > 0) {\n data.air = air;\n }\n\n if (input.data.battery) {\n data.battery = input.data.battery;\n }\n\n return { data: data };\n}\n\n/* ******************************************\n * bytes to number\n ********************************************/\n\nfunction readUInt16LE(bytes) {\n\n var value = (bytes[1] << 8) + bytes[0];\n\n return value & 0xffff;\n\n}\n\n\n\nfunction readInt16LE(bytes) {\n\n var ref = readUInt16LE(bytes);\n\n return ref > 0x7fff ? ref - 0x10000 : ref;\n\n}\n", + "environment": "javascript", + "storage": "", + "version": "1.0" + }, + "flows": { + "milesight_em300_th_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": "Main", + "widgets": [ + { + "layout": { + "col": 0, + "row": 0, + "sizeX": 2, + "sizeY": 5 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Temperature" + }, + "properties": { + "decimalPlaces": 2, + "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_em300_th_data", + "mapping": "temperature", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#d1311f", + "name": "Temperature", + "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": "Humidity" + }, + "properties": { + "decimalPlaces": 2, + "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": "%", + "unitSize": "20px" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "milesight_em300_th_data", + "mapping": "humidity", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#329fcd", + "name": "Humidity", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "text" + }, + { + "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, + "unit": "%" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "milesight_em300_th_data", + "mapping": "battery", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#2ebd59", + "name": "Battery", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "gauge" + }, + { + "layout": { + "col": 2, + "row": 0, + "sizeX": 4, + "sizeY": 10 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Temperature & Humidity (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 {\n title: {\n text: 'Temperature (°C)'\n },\n labels: {\n formatter: function (val) {\n if (val !== null && typeof val !== 'undefined')\n return val.toFixed(2);\n }\n }\n },\n {\n opposite: true,\n title: {\n text: 'Humidity (%)'\n },\n labels: {\n formatter: function (val) {\n if (val !== null && typeof val !== 'undefined')\n return val.toFixed(2);\n }\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_em300_th_data", + "mapping": "temperature", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#d1311f", + "name": "Temperature", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + }, + { + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "milesight_em300_th_data", + "mapping": "humidity", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#329fcd", + "name": "Humidity", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + } + ], + "type": "apex_charts" + }, + { + "layout": { + "col": 2, + "row": 10, + "sizeX": 4, + "sizeY": 5 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Battery (24h)" + }, + "properties": { + "alignTimeSeries": false, + "dataAppend": false, + "options": "var options = {\n chart: {\n type: 'line'\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 min: 0,\n max: 100,\n labels: {\n formatter: function (val) {\n if (val !== null && typeof val !== 'undefined')\n return val.toFixed(0) + '%';\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_em300_th_data", + "mapping": "battery", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#2ebd59", + "name": "Battery", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + } + ], + "type": "apex_charts" + } + ] + } + ] + } + } + ] + } + } + ] + } +} \ No newline at end of file