Plugin file
Plugin configuration file
{
"name": "the_things_node",
"version": "1.0.0",
"description": "The Things Node is a compact, IP54-rated device based on the SparkFun Pro Micro (3.3V/8MHz), featuring a Microchip LoRaWAN® module, temperature sensor, accelerometer, light sensor, button, and RGB LED",
"author": "Thinger.io",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/thinger-io/plugins.git",
"directory": "the-things-products-the-things-node"
},
"metadata": {
"name": "THE-THINGS-NODE",
"description": "The Things Node is a compact, IP54-rated device based on the SparkFun Pro Micro (3.3V/8MHz), featuring a Microchip LoRaWAN® module, temperature sensor, accelerometer, light sensor, button, and RGB LED",
"image": "assets/the-things-node.png",
"category": "devices",
"vendor": "the-things-products"
},
"resources": {
"products": [
{
"description": "The Things Node is a compact, IP54-rated device based on the SparkFun Pro Micro (3.3V/8MHz), featuring a Microchip LoRaWAN® module, temperature sensor, accelerometer, light sensor, button, and RGB LED",
"enabled": true,
"name": "THE-THINGS-NODE",
"product": "the_things_node",
"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": "ttn-.*"
},
"enabled": true
}
},
"buckets": {
"the_things_node_data": {
"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\nvar events = {\n 1: 'setup',\n 2: 'interval',\n 3: 'motion',\n 4: 'button',\n};\nvar colors = ['red', 'green', 'blue'];\n\nfunction decodeUplink(input) {\n var data = {};\n data.event = events[input.fPort];\n data.battery = (input.bytes[0] << 8) + input.bytes[1];\n data.light = (input.bytes[2] << 8) + input.bytes[3];\n data.temperature =\n (((input.bytes[4] & 0x80 ? input.bytes[4] - 0x100 : input.bytes[4]) << 8) +\n input.bytes[5]) /\n 100;\n return {\n data: data,\n };\n}\n",
"environment": "javascript",
"storage": "",
"version": "1.0"
},
"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": 6
},
"panel": {
"color": "#ffffff",
"currentColor": "#ffffff",
"showOffline": {
"type": "none"
},
"title": "Temperature"
},
"properties": {
"color": "#ff0000",
"max": 50,
"min": -10,
"unit": "°C"
},
"sources": [
{
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "temperature",
"tags": {
"device": [],
"group": []
}
},
"color": "#e74c3c",
"name": "Temperature",
"source": "bucket",
"timespan": {
"mode": "latest"
}
}
],
"type": "donutchart"
},
{
"layout": {
"col": 2,
"row": 0,
"sizeX": 2,
"sizeY": 6
},
"panel": {
"color": "#ffffff",
"currentColor": "#ffffff",
"showOffline": {
"type": "none"
},
"title": "Light Level"
},
"properties": {
"color": "#f1c40f",
"max": 1000,
"min": 0,
"unit": "lux"
},
"sources": [
{
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "light",
"tags": {
"device": [],
"group": []
}
},
"color": "#f39c12",
"name": "Light",
"source": "bucket",
"timespan": {
"mode": "latest"
}
}
],
"type": "donutchart"
},
{
"layout": {
"col": 4,
"row": 0,
"sizeX": 2,
"sizeY": 6
},
"panel": {
"color": "#ffffff",
"currentColor": "#ffffff",
"showOffline": {
"type": "none"
},
"title": "Battery"
},
"properties": {
"color": "#27ae60",
"max": 3300,
"min": 2000,
"unit": "mV"
},
"sources": [
{
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "battery",
"tags": {
"device": [],
"group": []
}
},
"color": "#2ecc71",
"name": "Battery",
"source": "bucket",
"timespan": {
"mode": "latest"
}
}
],
"type": "donutchart"
},
{
"layout": {
"col": 0,
"row": 6,
"sizeX": 3,
"sizeY": 12
},
"panel": {
"color": "#ffffff",
"currentColor": "#ffffff",
"showOffline": {
"type": "none"
},
"title": "Historic Temperature & Light"
},
"properties": {
"axis": true,
"fill": false,
"legend": true,
"multiple_axes": true
},
"sources": [
{
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "temperature",
"tags": {
"device": [],
"group": []
}
},
"color": "#e74c3c",
"name": "Temperature (°C)",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
},
{
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "light",
"tags": {
"device": [],
"group": []
}
},
"color": "#f39c12",
"name": "Light (lux)",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
}
],
"type": "chart"
},
{
"layout": {
"col": 3,
"row": 6,
"sizeX": 3,
"sizeY": 12
},
"panel": {
"color": "#ffffff",
"currentColor": "#ffffff",
"showOffline": {
"type": "none"
},
"title": "Recent Events"
},
"properties": {
"source": "code",
"template": "<div style=\"width:100%; height:100%; overflow-y:auto\">\n <table class=\"table table-striped table-condensed\">\n <thead>\n <tr>\n <th>Time</th>\n <th>Event</th>\n <th>Temperature</th>\n <th>Light</th>\n <th>Battery</th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat=\"entry in value\">\n <td>{{ entry.ts | date:'short' }}</td>\n <td><span class=\"label label-info\">{{ entry.event || '—' }}</span></td>\n <td>{{ entry.temperature ? (entry.temperature + ' °C') : '—' }}</td>\n <td>{{ entry.light ? (entry.light + ' lux') : '—' }}</td>\n <td>{{ entry.battery ? (entry.battery + ' mV') : '—' }}</td>\n </tr>\n </tbody>\n </table>\n</div>"
},
"sources": [
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "ts",
"tags": {
"device": [],
"group": []
}
},
"color": "#3498db",
"name": "timestamp",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
},
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "event",
"tags": {
"device": [],
"group": []
}
},
"color": "#9b59b6",
"name": "event",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
},
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "temperature",
"tags": {
"device": [],
"group": []
}
},
"color": "#e74c3c",
"name": "temperature",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
},
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "light",
"tags": {
"device": [],
"group": []
}
},
"color": "#f39c12",
"name": "light",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
},
{
"aggregation": {},
"bucket": {
"backend": "mongodb",
"id": "the_things_node_data",
"mapping": "battery",
"tags": {
"device": [],
"group": []
}
},
"color": "#2ecc71",
"name": "battery",
"source": "bucket",
"timespan": {
"magnitude": "hour",
"mode": "relative",
"period": "latest",
"value": 24
}
}
],
"type": "html_time"
}
]
}
]
}
}
]
}
}
]
}
}