Skip to content

Plugin file

Plugin configuration file
{
  "name": "arduino_lora_vision_shield",
  "version": "1.0.0",
  "description": "The Arduino Portenta Vision Shield LoRa® includes a 320×320 camera and dual microphones for embedded vision and sound detection applications.",
  "author": "Thinger.io",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/thinger-io/plugins.git",
    "directory": "arduino-lora-vision-shield"
  },
  "metadata": {
    "name": "Arduino LORA-VISION-SHIELD",
    "description": "The Arduino Portenta Vision Shield LoRa® includes a 320×320 camera and dual microphones for embedded vision and sound detection applications.",
    "image": "assets/visionshield.png",
    "category": "devices",
    "vendor": "arduino"
  },
  "resources": {
    "products": [
      {
        "description": "The Arduino Portenta Vision Shield LoRa® includes a 320×320 camera and dual microphones for embedded vision and sound detection applications.",
        "enabled": true,
        "name": "Arduino LORA-VISION-SHIELD",
        "product": "arduino_lora_vision_shield",
        "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-vision-.*"
              },
              "enabled": true
            }
          },
          "buckets": {
            "arduino_lora_vision_shield_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": []
        }
      }
    ]
  }
}