Skip to content

Plugin file

Plugin configuration file
{
  "name": "arduino_mkr_wan_1310",
  "version": "1.0.0",
  "description": "The Arduino MKR WAN 1310 is a development board that adds LoRaWAN connectivity to projects requiring long-range, low-power wireless communication. It allows easy connection of sensors and actuators.",
  "author": "Thinger.io",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/thinger-io/plugins.git",
    "directory": "arduino-mkr-wan-1310"
  },
  "metadata": {
    "name": "Arduino MKR-WAN-1310",
    "description": "The Arduino MKR WAN 1310 is a development board that adds LoRaWAN connectivity to projects requiring long-range, low-power wireless communication. It allows easy connection of sensors and actuators.",
    "image": "assets/mkrwan1310.png",
    "category": "devices",
    "vendor": "arduino"
  },
  "resources": {
    "products": [
      {
        "description": "The Arduino MKR WAN 1310 is a development board that adds LoRaWAN connectivity to projects requiring long-range, low-power wireless communication. It allows easy connection of sensors and actuators.",
        "enabled": true,
        "name": "Arduino MKR-WAN-1310",
        "product": "arduino_mkr_wan_1310",
        "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": "arduino-mkr-wan-1310-.*"
              },
              "enabled": true
            }
          },
          "buckets": {
            "arduino_mkr_wan_1310_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\n// This is used with the LoRa LED/ON off basic sketch\n// Please refer to https://create.arduino.cc/editor/FT-CONTENT/043f42fb-2b04-4cfb-a277-b1a3dd5366c2/preview\n\nvar LED_STATES = ['off', 'on']\n\nfunction decodeUplink(input) {\n  var data = {};\n  data.ledState = LED_STATES[input.bytes[0]];\n  return {\n    data: data,\n  };\n}\n\nfunction encodeDownlink(input) {\n  var i = LED_STATES.indexOf(input.data.ledState);\n  if (i === -1) {\n    return {\n      errors: ['unknown led state'],\n    };\n  }\n  return {\n    bytes: [i],\n    fPort: 1,\n  };\n}\n\nfunction decodeDownlink(input) {\n  return {\n    data: {\n      ledState: LED_STATES[input.bytes[0]]\n    }\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": "Current LED State"
                        },
                        "properties": {
                          "source": "code",
                          "template": "<div style=\"width:100%; height:100%; display:flex; align-items:center; justify-content:center; font-size:48px; font-weight:bold;\">\n  <span ng-if=\"value[0] === 'on'\" style=\"color:#2ecc71;\">● ON</span>\n  <span ng-if=\"value[0] === 'off'\" style=\"color:#95a5a6;\">○ OFF</span>\n  <span ng-if=\"!value[0]\" style=\"color:#e74c3c;\">NO DATA</span>\n</div>"
                        },
                        "sources": [
                          {
                            "bucket": {
                              "backend": "mongodb",
                              "id": "arduino_mkr_wan_1310_data",
                              "mapping": "ledState",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#1abc9c",
                            "name": "LED State",
                            "source": "bucket",
                            "timespan": {
                              "mode": "latest"
                            }
                          }
                        ],
                        "type": "html_time"
                      },
                      {
                        "layout": {
                          "col": 2,
                          "row": 0,
                          "sizeX": 4,
                          "sizeY": 12
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "LED State History"
                        },
                        "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>Timestamp</th>\n        <th>LED State</th>\n      </tr>\n    </thead>\n    <tbody>\n      <tr ng-repeat=\"entry in value\">\n        <td>{{ entry.ts | date:'medium' }}</td>\n        <td>\n          <span ng-if=\"entry.ledState === 'on'\" style=\"color:#2ecc71; font-weight:bold;\">● ON</span>\n          <span ng-if=\"entry.ledState === 'off'\" style=\"color:#95a5a6;\">○ OFF</span>\n        </td>\n      </tr>\n    </tbody>\n  </table>\n</div>"
                        },
                        "sources": [
                          {
                            "aggregation": {},
                            "bucket": {
                              "backend": "mongodb",
                              "id": "arduino_mkr_wan_1310_data",
                              "mapping": "ts",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#1abc9c",
                            "name": "ts",
                            "source": "bucket",
                            "timespan": {
                              "magnitude": "hour",
                              "mode": "relative",
                              "period": "latest",
                              "value": 24
                            }
                          },
                          {
                            "aggregation": {},
                            "bucket": {
                              "backend": "mongodb",
                              "id": "arduino_mkr_wan_1310_data",
                              "mapping": "ledState",
                              "tags": {
                                "device": [],
                                "group": []
                              }
                            },
                            "color": "#3498db",
                            "name": "ledState",
                            "source": "bucket",
                            "timespan": {
                              "magnitude": "hour",
                              "mode": "relative",
                              "period": "latest",
                              "value": 24
                            }
                          }
                        ],
                        "type": "html_time"
                      },
                      {
                        "layout": {
                          "col": 0,
                          "row": 6,
                          "sizeX": 2,
                          "sizeY": 6
                        },
                        "panel": {
                          "color": "#ffffff",
                          "currentColor": "#ffffff",
                          "showOffline": {
                            "type": "none"
                          },
                          "title": "Device Info"
                        },
                        "properties": {
                          "source": "code",
                          "template": "<div style=\"padding:15px; font-size:14px;\">\n  <p><strong>Product:</strong> Arduino MKR WAN 1310</p>\n  <p><strong>Type:</strong> LoRaWAN Development Board</p>\n  <p><strong>Features:</strong></p>\n  <ul>\n    <li>Long-range LoRaWAN® connectivity</li>\n    <li>ATECC508 secure element</li>\n    <li>Battery charger</li>\n    <li>2MB SPI Flash</li>\n    <li>Low power: 104 µA</li>\n  </ul>\n</div>"
                        },
                        "sources": [],
                        "type": "text"
                      }
                    ]
                  }
                ]
              }
            }
          ]
        }
      }
    ]
  }
}