diff --git a/example-windsensor/CHANGELOG.md b/example-windsensor/CHANGELOG.md new file mode 100644 index 00000000..dda6ac59 --- /dev/null +++ b/example-windsensor/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 1.0.0 - 2026-01-15 + +- First version of plugin \ No newline at end of file diff --git a/example-windsensor/LICENSE.md b/example-windsensor/LICENSE.md new file mode 100644 index 00000000..bffeef34 --- /dev/null +++ b/example-windsensor/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/example-windsensor/README.md b/example-windsensor/README.md new file mode 100644 index 00000000..3ed8ad00 --- /dev/null +++ b/example-windsensor/README.md @@ -0,0 +1,37 @@ +Based on the provided device data and template, here is the README.md: + +# Wind Sensor + +The Wind Sensor is a LoRaWAN-enabled device designed for wind monitoring applications. It features integrated wind measurement capabilities combined with a controllable LED indicator for status visualization and signaling purposes. + +## Thinger.io Integration + +## Requirements + +A LoRaWAN server is required to communicate the Wind Sensor 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://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 for LED control. + +## Additional Resources + +- [Thinger.io Documentation](https://docs.thinger.io) \ No newline at end of file diff --git a/example-windsensor/assets/example-windsensor.png b/example-windsensor/assets/example-windsensor.png new file mode 100644 index 00000000..ba932d67 Binary files /dev/null and b/example-windsensor/assets/example-windsensor.png differ diff --git a/example-windsensor/plugin.json b/example-windsensor/plugin.json new file mode 100644 index 00000000..6d98b305 --- /dev/null +++ b/example-windsensor/plugin.json @@ -0,0 +1,596 @@ +{ + "name": "example_windsensor", + "version": "1.0.0", + "description": "LoRaWAN Wind Sensor with controllable LED for environmental monitoring", + "author": "Thinger.io", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/thinger-io/plugins.git", + "directory": "example-windsensor" + }, + "metadata": { + "name": "example_windsensor", + "description": "LoRaWAN Wind Sensor with controllable LED for environmental monitoring", + "image": "assets/windsensor.png", + "category": "devices", + "vendor": "example" + }, + "resources": { + "products": [ + { + "description": "LoRaWAN Wind Sensor with controllable LED for environmental monitoring", + "enabled": true, + "name": "example_windsensor", + "product": "example_windsensor", + "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": { + "example_windsensor_autoprovision": { + "config": { + "mode": "pattern", + "pattern": "wind-sensor-.*" + }, + "enabled": true + } + }, + "buckets": { + "example_windsensor_data_bucket": { + "backend": "mongodb", + "data": { + "payload": "{{payload}}", + "payload_function": "parseOrDecodeIncomingData", + "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\nvar directions = ['N', 'E', 'S', 'W'];\nvar colors = ['red', 'green'];\nvar degrees = {\n N: 0,\n E: 90,\n S: 180,\n W: 270,\n};\n\nfunction decodeUplink(input) {\n switch (input.fPort) {\n case 1:\n return {\n // Decoded data\n data: {\n direction: directions[input.bytes[0]],\n speed: input.bytes[1],\n },\n };\n default:\n return {\n errors: ['unknown FPort'],\n };\n }\n}\n\nfunction normalizeUplink(input) {\n return {\n // Normalized data\n data: {\n wind: {\n direction: degrees[input.data.direction], // letter to degrees\n speed: input.data.speed * 0.5144, // knots to m/s\n },\n },\n };\n}\n\nfunction encodeDownlink(input) {\n var i = colors.indexOf(input.data.led);\n if (i === -1) {\n return {\n errors: ['invalid LED color'],\n };\n }\n return {\n // LoRaWAN FPort used for the downlink message\n fPort: 2,\n // Encoded bytes\n bytes: [i],\n };\n}\n\nfunction decodeDownlink(input) {\n switch (input.fPort) {\n case 2:\n return {\n // Decoded downlink (must be symmetric with encodeDownlink)\n data: {\n led: colors[input.bytes[0]],\n },\n };\n default:\n return {\n errors: ['invalid FPort'],\n };\n }\n}\n", + "environment": "javascript", + "storage": "", + "version": "1.0" + }, + "properties": { + "example_windsensor_led_status": { + "data": { + "payload": "{{payload.led_status}}", + "payload_function": "", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "default": { + "value": false + }, + "enabled": true + }, + "example_windsensor_wind_gust": { + "data": { + "payload": "{{payload.wind_gust}}", + "payload_function": "", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "default": { + "value": 0 + }, + "enabled": true + }, + "example_windsensor_wind_speed": { + "data": { + "payload": "{{payload.wind_speed}}", + "payload_function": "", + "payload_type": "source_payload", + "resource": "uplink", + "source": "resource", + "update": "events" + }, + "default": { + "value": 0 + }, + "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": [ + { + "description": "", + "name": "", + "property": "example_windsensor_wind_speed", + "type": "", + "value": 0 + }, + { + "description": "", + "name": "", + "property": "example_windsensor_wind_gust", + "type": "", + "value": 0 + }, + { + "description": "", + "name": "", + "property": "example_windsensor_led_status", + "type": "", + "value": false + }, + { + "property": "dashboard", + "value": { + "tabs": [ + { + "name": "Wind Monitoring", + "widgets": [ + { + "layout": { + "col": 0, + "row": 0, + "sizeX": 6, + "sizeY": 12 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Historic Wind Speed" + }, + "properties": { + "axis": true, + "fill": false, + "legend": true, + "multiple_axes": true + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "example_windsensor_data_bucket", + "mapping": "wind_speed", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#1E88E5", + "name": "Wind Speed (m/s)", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + }, + { + "bucket": { + "backend": "mongodb", + "id": "example_windsensor_data_bucket", + "mapping": "wind_gust", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#FF5722", + "name": "Wind Gust (m/s)", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + } + ], + "type": "chart" + }, + { + "layout": { + "col": 6, + "row": 0, + "sizeX": 3, + "sizeY": 6 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Current Wind Speed" + }, + "properties": { + "color": "#1E88E5", + "max": 30, + "min": 0, + "unit": "m/s" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "example_windsensor_data_bucket", + "mapping": "wind_speed", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#1E88E5", + "name": "Source 1", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "donutchart" + }, + { + "layout": { + "col": 9, + "row": 0, + "sizeX": 3, + "sizeY": 6 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Wind Direction" + }, + "properties": { + "color": "#4CAF50", + "max": 360, + "min": 0, + "unit": "°" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "example_windsensor_data_bucket", + "mapping": "wind_direction", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#4CAF50", + "name": "Source 1", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "donutchart" + }, + { + "layout": { + "col": 6, + "row": 6, + "sizeX": 3, + "sizeY": 6 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Peak Wind Gust" + }, + "properties": { + "color": "#FF5722", + "max": 40, + "min": 0, + "unit": "m/s" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "example_windsensor_data_bucket", + "mapping": "wind_gust", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#FF5722", + "name": "Source 1", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "donutchart" + }, + { + "layout": { + "col": 9, + "row": 6, + "sizeX": 3, + "sizeY": 6 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Battery" + }, + "properties": { + "color": "#FFC107", + "max": 4.2, + "min": 3, + "unit": "V" + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "example_windsensor_data_bucket", + "mapping": "battery_voltage", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#FFC107", + "name": "Source 1", + "source": "bucket", + "timespan": { + "mode": "latest" + } + } + ], + "type": "donutchart" + }, + { + "layout": { + "col": 0, + "row": 12, + "sizeX": 6, + "sizeY": 6 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Wind Direction History" + }, + "properties": { + "axis": true, + "fill": false, + "legend": true, + "multiple_axes": true + }, + "sources": [ + { + "bucket": { + "backend": "mongodb", + "id": "example_windsensor_data_bucket", + "mapping": "wind_direction", + "tags": { + "device": [], + "group": [] + } + }, + "color": "#4CAF50", + "name": "Direction (°)", + "source": "bucket", + "timespan": { + "magnitude": "hour", + "mode": "relative", + "period": "latest", + "value": 24 + } + } + ], + "type": "chart" + }, + { + "layout": { + "col": 6, + "row": 12, + "sizeX": 6, + "sizeY": 6 + }, + "panel": { + "color": "#ffffff", + "currentColor": "#ffffff", + "showOffline": { + "type": "none" + }, + "title": "Recent Wind Data" + }, + "properties": { + "source": "code", + "template": "
| Time | \r\nSpeed (m/s) | \r\nDirection (°) | \r\nGust (m/s) | \r\nBattery (V) | \r\n
|---|---|---|---|---|
| {{ entry.ts | date:'HH:mm:ss' }} | \r\n{{ entry.wind_speed || '—' }} | \r\n{{ entry.wind_direction || '—' }} | \r\n{{ entry.wind_gust || '—' }} | \r\n{{ entry.battery_voltage || '—' }} | \r\n