{
  "name": "ThingPark Actility Downlink Converter",
  "type": "DOWNLINK",
  "integrationType": "THINGPARK",
  "debugMode": false,
  "debugSettings": {
    "failuresEnabled": true,
    "allEnabled": false,
    "allEnabledUntil": 0
  },
  "configuration": {
    "scriptLang": "JS",
    "decoder": null,
    "tbelDecoder": "/**\n * Decodes the incoming payload and returns a structured object containing telemetry data and attributes.\n *\n * @param {byte[]} input - The raw payload received as an array of bytes.\n * @returns {Object} output - The structured output with decoded telemetry and attributes.\n */\n\nfunction decodePayload(input) {\n    // Initialize the output object with empty attributes and telemetry for clarity.\n    var result = { attributes: {}, telemetry: {}};\n\n    // Decode serial number (SN) from the first 4 bytes of the payload.\n    // Press '?' icon in the top right corner to learn more about built in helper functions and capabilities.\n    result.attributes.sn = parseBytesToInt(input, 0, 4);\n\n    // Extract the timestamp from metadata (represented in milliseconds).\n    var timestamp = metadata.ts; // ts is the timestamp parsed from the incoming message's time, or returns the current time if it cannot be parsed.\n\n    // Initialize an object to store decoded key/value telemetry data.\n    var values = {};\n\n    // Decode battery level from the 5th byte of the payload.\n    values.battery = parseBytesToInt(input, 4, 1);\n\n    // Decode temperature from the 6th and 7th bytes of the payload (divided by 100).\n    values.temperature = parseBytesToInt(input, 5, 2) / 100.0;\n\n    // Decode saturation from the 8th byte of the payload.\n    values.saturation = parseBytesToInt(input, 7, 1);\n\n    // Combine the timestamp with values and add it to the telemetry.\n    result.telemetry = {\n        ts: timestamp,\n        values: values\n    };\n\n    // Return the fully constructed output object.\n    return result;\n    // Same logic, less code:\n    // return {\n    //     attributes: {\n    //         sn: parseBytesToInt(input, 0, 4)\n    //     },\n    //     telemetry: {\n    //         ts: convertDateToTimestamp(metadata.time),\n    //         values: {\n    //             battery: parseBytesToInt(input, 4, 1),\n    //             temperature: parseBytesToInt(input, 5, 2) / 100.0,\n    //             saturation: parseBytesToInt(input, 7, 1)\n    //         }\n    //     }\n    // };\n}\n\nvar result = decodePayload(payload);\n// Uncomment this code block to overwrite values set in the main configuration window. Useful if you extract device/asset/customer/group names from the payload;\n// result.type = 'DEVICE'; // Entity type allows you to choose type of created entity. Can be 'DEVICE' or 'ASSET'.\n// result.name = 'Temperature Sensor'; // Device or asset name (the value must be unique)\n// result.profile = 'IndustrialSensorProfile'; // Device or asset profile name.\n// result.customer = 'MyCustomer'; // If customer is not null - created entity will be assigned to customer with such name.\n// result.group = 'SensorsGroup'; // If group is not null - created entity will be added to the entity group with such name.\n\n// Return the final result object.\nreturn result;",
    "encoder": "var data = {};\n\ndata.senPayloadHex = msg.sentPayloadHex;\ndata.deviceName = metadata['deviceName'];\n\nvar result = {\n    contentType: \"JSON\",\n    data: JSON.stringify(data),\n};\n\nreturn result;",
    "tbelEncoder": "// Encode downlink data from incoming Rule Engine message\n\n// msg - JSON message payload downlink message json\n// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.\n// metadata - list of key-value pairs with additional data about the message\n// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter\n\n/** Encoder **/\n\nvar data = {};\n\n// Process data from incoming message and metadata\n\ndata.tempFreq = msg.temperatureUploadFrequency;\ndata.humFreq = msg.humidityUploadFrequency;\n\ndata.devSerialNumber = metadata['ss_serialNumber'];\n\n// Result object with encoded downlink payload\nvar result = {\n\n    // downlink data content type: JSON, TEXT or BINARY (base64 format)\n    contentType: \"JSON\",\n\n    // downlink data\n    data: JSON.stringify(data),\n\n    // Optional metadata object presented in key/value format\n    metadata: {\n            topic: metadata['deviceType']+'/'+metadata['deviceName']+'/upload'\n    }\n\n};\n\nreturn result;",
    "updateOnlyKeys": [
      "eui",
      "fPort",
      "adr",
      "spreadingFactor",
      "bandwidth",
      "devAddr",
      "frequency",
      "class"
    ]
  },
  "additionalInfo": {
    "description": ""
  },
  "edgeTemplate": false,
  "converterVersion": 1
}