diff --git a/elspina-em-elst01/CHANGELOG.md b/elspina-em-elst01/CHANGELOG.md new file mode 100644 index 00000000..142279b5 --- /dev/null +++ b/elspina-em-elst01/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.0.0 - 2026-01-17 + +- First version of plugin \ No newline at end of file diff --git a/elspina-em-elst01/LICENSE.md b/elspina-em-elst01/LICENSE.md new file mode 100644 index 00000000..bffeef34 --- /dev/null +++ b/elspina-em-elst01/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/elspina-em-elst01/README.md b/elspina-em-elst01/README.md new file mode 100644 index 00000000..513772c8 --- /dev/null +++ b/elspina-em-elst01/README.md @@ -0,0 +1,55 @@ +Based on the device name pattern (EM-ELST01) and the description provided about accelerometer and switch sensor capabilities, I can create a README following the template structure with the available information. + +```markdown +# EM-ELST01 LoRaWAN Accelerometer & Switch Sensor + +The EM-ELST01 is a LoRaWAN-enabled device designed to capture state changes through its integrated accelerometer and switch sensor. This compact device enables remote monitoring of motion events and contact states, making it ideal for asset tracking, door/window monitoring, and equipment status detection applications. + +## Key Features + +- Built-in accelerometer for motion and vibration detection +- Switch sensor for contact state monitoring +- LoRaWAN connectivity for long-range, low-power communication +- State change event detection and reporting +- Compact design for easy deployment + +## Typical Applications + +- Door and window open/close detection +- Asset movement monitoring +- Equipment tamper detection +- Vibration-based machine status monitoring +- Tilt and orientation sensing + +## Thinger.io Integration + +## Requirements + +A LoRaWAN server is required to communicate the EM-ELST01 with 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://ma.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 + +- [Thinger.io Documentation](https://docs.thinger.io) +``` \ No newline at end of file diff --git a/elspina-em-elst01/assets/elspina-em-elst01.png b/elspina-em-elst01/assets/elspina-em-elst01.png new file mode 100644 index 00000000..2137c044 Binary files /dev/null and b/elspina-em-elst01/assets/elspina-em-elst01.png differ diff --git a/elspina-em-elst01/plugin.json b/elspina-em-elst01/plugin.json new file mode 100644 index 00000000..dc77aa36 --- /dev/null +++ b/elspina-em-elst01/plugin.json @@ -0,0 +1,422 @@ +{ + "name": "elspina_em_elst01", + "version": "1.0.0", + "description": "LoRaWAN accelerometer and switch sensor for state change detection", + "author": "Thinger.io", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/thinger-io/plugins.git", + "directory": "elspina-em-elst01" + }, + "metadata": { + "name": "elspina_em-elst01", + "description": "LoRaWAN accelerometer and switch sensor for state change detection", + "image": "assets/em-elst01-e.jpg", + "category": "devices", + "vendor": "elspina" + }, + "resources": { + "products": [ + { + "description": "LoRaWAN accelerometer and switch sensor for state change detection", + "enabled": true, + "name": "elspina_em-elst01", + "product": "elspina_em_elst01", + "profile": { + "api": { + "downlink": { + "enabled": true, + "handle_connectivity": false, + "request": { + "data": { + "path": "/downlink", + "payload": "{\n \"data\" : \"{{payload.data=\"\"}}\",\n \"port\" : {{payload.port=85}},\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": { + "device_id_resolver": "getId", + "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": "em-elst01-.*" + }, + "enabled": true + } + }, + "buckets": { + "elspina_em_elst01_data_bucket": { + "backend": "mongodb", + "data": { + "payload": "{{payload}}", + "payload_function": "decodeThingerUplink", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "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 // Decode an uplink message from a buffer\n // (array) of bytes to an object of fields.\n var port = input.fPort;\n var bytes = input.bytes;\n var switch_status = (bytes[0]>>4)&0xFF;\n var value=(bytes[0]<<8 | bytes[1]) & 0x0FFF;\n var batV=value/1000;//Battery,units:V\n \n if(bytes.length == 4)\n {\n var tnomd = (bytes[2]<<8 | bytes[3]) & 0xFFFF;\n return {\n status:switch_status,\n Bat:batV ,\n TNOMD:tnomd,\n };\n }\n else if(bytes.length == 9)\n {\n var tode = (bytes[2]<<16 | bytes[3]<<8 | bytes[4]) & 0xFFFFFF;\n var ldod = (bytes[5]<<16 | bytes[6]<<8 | bytes[7]) & 0xFFFFFF;\n var alarm = bytes[8];\n return {\n status:switch_status,\n Bat:batV ,\n TODE:tode,\n LDOD:ldod,\n ALARM:alarm,\n };\n }\n else if(bytes.length == 19)\n {\n var tode1 = (bytes[2]<<16 | bytes[3]<<8 | bytes[4]) & 0xFFFFFF;\n var ldod1 = (bytes[5]<<16 | bytes[6]<<8 | bytes[7]) & 0xFFFFFF;\n var alarm1 = bytes[8];\n var tnomd1 = (bytes[9]<<8 | bytes[10]) & 0xFFFF;\n \n value=bytes[11]<<8 | bytes[12];\n var X = 0;\n if(bytes[11]>>4 == 0x0F)\n X=((value-0xFFFF)/100).toFixed(2);\n else\n X=(value/100).toFixed(2);\n \n value=bytes[13]<<8 | bytes[14];\n var Y=0;\n if(bytes[13]>>4 == 0x0F)\n Y=((value-0xFFFF)/100).toFixed(2);\n else\n Y=(value/100).toFixed(2);\n \n value=bytes[15]<<8 | bytes[16];\n var Z=0;\n if(bytes[15]>>4 == 0x0F)\n Z=((value-0xFFFF)/100).toFixed(2);\n else\n Z=(value/100).toFixed(2);\n \n value=bytes[17]<<8 | bytes[18];\n var temp_DS18B20=0;//DS18B20,temperature,units:°C\n if(bytes[17]>>4 == 0x0F)\n temp_DS18B20=((value-0xFFFF)/10).toFixed(1);\n else\n temp_DS18B20=(value/10).toFixed(1);\n return {\n data:{\n status:switch_status,\n Bat:batV ,\n TODE:tode1,\n LDOD:ldod1,\n ALARM:alarm1,\n TNOMD:tnomd1,\n X:X,\n Y:Y,\n Z:Z,\n temp_ds:temp_DS18B20\n },\n };\n }\n }", + "environment": "javascript", + "storage": "", + "version": "1.0" + }, + "properties": { + "elspina_em_elst01_battery_level": { + "data": { + "payload": "{{payload.battery}}", + "payload_function": "", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "default": {}, + "enabled": true + }, + "elspina_em_elst01_switch_state": { + "data": { + "payload": "{{payload.switch_state}}", + "payload_function": "", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "default": {}, + "enabled": true + }, + "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": "Monitoring", + "widgets": [ + { + "layout": { + "col": 0, + "row": 0, + "sizeX": 3, + "sizeY": 6 + }, + "panel": { + "color": "#1976D2", + "currentColor": "#1976D2", + "showOffline": { + "type": "last_sample" + }, + "title": "Switch State" + }, + "properties": { + "color": "#4CAF50", + "max": 1, + "min": 0, + "unit": "" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "switch_state", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#4CAF50", + "name": "Switch", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "donutchart" + }, + { + "layout": { + "col": 3, + "row": 0, + "sizeX": 3, + "sizeY": 6 + }, + "panel": { + "color": "#F57C00", + "currentColor": "#F57C00", + "showOffline": { + "type": "last_sample" + }, + "title": "Battery Level" + }, + "properties": { + "color": "#FFC107", + "max": 100, + "min": 0, + "unit": "%" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "battery", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#FFC107", + "name": "Battery", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "donutchart" + }, + { + "layout": { + "col": 0, + "row": 6, + "sizeX": 6, + "sizeY": 12 + }, + "panel": { + "color": "#424242", + "currentColor": "#424242", + "showFullscreen": true, + "showOffline": { + "type": "none" + }, + "title": "State Change Events - Last 24 Hours" + }, + "properties": { + "alignTimeSeries": false, + "dataAppend": false, + "options": "var options = {\n series: series,\n chart: {\n type: 'line',\n background: '#424242',\n toolbar: {\n show: true,\n autoSelected: 'zoom'\n },\n zoom: {\n enabled: true,\n type: 'x',\n autoScaleYaxis: true\n }\n },\n stroke: {\n curve: 'stepline',\n width: 2\n },\n markers: {\n size: 4,\n strokeWidth: 0,\n hover: {\n size: 6\n }\n },\n xaxis: {\n type: 'datetime',\n labels: {\n datetimeUTC: false,\n style: {\n colors: '#FFFFFF'\n }\n }\n },\n yaxis: {\n labels: {\n formatter: function(val) {\n return val === 1 ? 'ON' : 'OFF';\n },\n style: {\n colors: '#FFFFFF'\n }\n },\n min: 0,\n max: 1\n },\n tooltip: {\n x: {\n format: 'dd/MM/yyyy HH:mm:ss'\n },\n shared: true\n },\n legend: {\n position: 'bottom',\n labels: {\n colors: '#FFFFFF'\n }\n },\n grid: {\n borderColor: '#555',\n row: {\n colors: ['#333', 'transparent'],\n opacity: 0.5\n }\n }\n};", + "realTimeUpdate": false + }, + "sources": [ + { + "$timespan": { + "magnitude": "day", + "mode": "configurable", + "period": "latest", + "value": 1 + }, + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "switch_state", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#4CAF50", + "name": "Switch State", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + }, + { + "$timespan": { + "magnitude": "day", + "mode": "configurable", + "period": "latest", + "value": 1 + }, + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "accelerometer_state", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#2196F3", + "name": "Accelerometer State", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + } + ], + "type": "apex_charts" + }, + { + "layout": { + "col": 6, + "row": 0, + "sizeX": 6, + "sizeY": 18 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Event History - Last 50 Events" + }, + "properties": { + "source": "code", + "template": "
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
TimestampSwitch StateAccelerometerBattery (%)
{{ entry.ts | date:'medium' }}\n ON\n OFF\n \n {{ entry.accelerometer_state || '—' }}{{ entry.battery || '—' }}
\n
" + }, + "sources": [ + { + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "ts", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#555", + "name": "timestamp", + "source": "bucket", + "timespan": { + "magnitude": "day", + "mode": "relative", + "period": "latest", + "value": 7 + } + }, + { + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "switch_state", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#4CAF50", + "name": "switch_state", + "source": "bucket", + "timespan": { + "magnitude": "day", + "mode": "relative", + "period": "latest", + "value": 7 + } + }, + { + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "accelerometer_state", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#2196F3", + "name": "accelerometer_state", + "source": "bucket", + "timespan": { + "magnitude": "day", + "mode": "relative", + "period": "latest", + "value": 7 + } + }, + { + "aggregation": {}, + "bucket": { + "backend": "mongodb", + "id": "elspina_em_elst01_data_bucket", + "mapping": "battery", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#FFC107", + "name": "battery", + "source": "bucket", + "timespan": { + "magnitude": "day", + "mode": "relative", + "period": "latest", + "value": 7 + } + } + ], + "type": "html_time" + } + ] + } + ] + } + } + ] + } + } + ] + } +} \ No newline at end of file