Skip to content

Commit

Permalink
Added an additional test cases for loriot integration(elsys devices)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-barysh-dev committed Dec 24, 2024
1 parent 4c32451 commit 9530be3
Show file tree
Hide file tree
Showing 17 changed files with 498 additions and 10 deletions.
9 changes: 7 additions & 2 deletions VENDORS/Elsys/ERS2/LORIOT/uplink/converter.json

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions VENDORS/Elsys/ERS2/LORIOT/uplink/payload_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"cmd": "gw",
"seqno": 4,
"EUI": "0102030405060708",
"ts": 1690901260493,
"fcnt": 3,
"port": 207,
"freq": 868300000,
"toa": 1319,
"dr": "SF12 BW125 4/5",
"ack": false,
"gws": [
{
"rssi": -38,
"snr": 8.5,
"ts": 1690901260493,
"time": "2023-08-01T14:47:40.493Z",
"gweui": "1020304080706050",
"ant": 0
},
{
"rssi": -42,
"snr": 8.8,
"ts": 1690901260495,
"time": "2023-08-01T14:47:40.495Z",
"gweui": "1020304081716151",
"ant": 0
}
],
"bat": 143,
"data": "0100e202290400270506060308070d62"
}
45 changes: 45 additions & 0 deletions VENDORS/Elsys/ERS2/LORIOT/uplink/result_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[{
"deviceName": "ERS2 0102030405060708",
"deviceType": "ERS2",
"attributes": {
"eui": "0102030405060708",
"fPort": 207,
"frequency": 868300000
},
"telemetry": [{
"ts": 1690901260493,
"values": {
"temperature": 22.6,
"humidity": 41,
"light": 39,
"pir": 6,
"vdd": 3426
}
}]
}, {
"deviceName": "Gateway 1020304080706050",
"deviceType": "Lora gateway",
"telemetry": [{
"ts": 1690901260493,
"values": {
"rssi": -38,
"snr": 8.5
}
}],
"attributes": {
"eui": "1020304080706050"
}
}, {
"deviceName": "Gateway 1020304081716151",
"deviceType": "Lora gateway",
"telemetry": [{
"ts": 1690901260495,
"values": {
"rssi": -42,
"snr": 8.8
}
}],
"attributes": {
"eui": "1020304081716151"
}
}]
9 changes: 7 additions & 2 deletions VENDORS/Elsys/ERS2_CO2/LORIOT/uplink/converter.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"name": "Loriot Uplink Decoder for Elsys ERS2 C02 Device",
"type": "UPLINK",
"debugMode": true,
"debugMode": false,
"debugSettings": {
"failuresEnabled": true,
"allEnabled": false,
"allEnabledUntil": 1735046693295
},
"configuration": {
"scriptLang": "TBEL",
"decoder": "// Decode an uplink message from a buffer\n// payload - array of bytes\n// metadata - key/value object\n\n/** Decoder **/\n\n// decode payload to string\nvar payloadStr = decodeToString(payload);\n\n// decode payload to JSON\n// var data = decodeToJson(payload);\n\nvar deviceName = 'Device A';\nvar deviceType = 'thermostat';\nvar customerName = 'Customer C';\nvar groupName = 'thermostat devices';\nvar manufacturer = 'Example corporation';\n// use assetName and assetType instead of deviceName and deviceType\n// to automatically create assets instead of devices.\n// var assetName = 'Asset A';\n// var assetType = 'building';\n\n// Result object with device/asset attributes/telemetry data\nvar result = {\n// Use deviceName and deviceType or assetName and assetType, but not both.\n deviceName: deviceName,\n deviceType: deviceType,\n// assetName: assetName,\n// assetType: assetType,\n// customerName: customerName,\n groupName: groupName,\n attributes: {\n model: 'Model A',\n serialNumber: 'SN111',\n integrationName: metadata['integrationName'],\n manufacturer: manufacturer\n },\n telemetry: {\n temperature: 42,\n humidity: 80,\n rawData: payloadStr\n }\n};\n\n/** Helper functions **/\n\nfunction decodeToString(payload) {\n return String.fromCharCode.apply(String, payload);\n}\n\nfunction decodeToJson(payload) {\n // covert payload to string.\n var str = decodeToString(payload);\n\n // parse string to JSON\n var data = JSON.parse(str);\n return data;\n}\n\nreturn result;",
"tbelDecoder": "var data = decodeToJson(payload);\nvar deviceName = \"ERS2 CO2 \" + data.EUI;\nvar deviceType = \"ERS2 CO2\";\nvar groupName = null; // If groupName is not null - created device will be added to the entity group with such name.\nvar customerName = null; // If customerName is not null - created devices will be assigned to customer with such name. \n\n// use assetName and assetType instead of deviceName and deviceType\n// to automatically create assets instead of devices.\n// var assetName = 'Asset A';\n// var assetType = 'building';\n\n// If you want to parse incoming data somehow, you can add your code to this function.\n// input: bytes\n// expected output:\n// {\n// \"attributes\": {\"attributeKey\": \"attributeValue\"},\n// \"telemetry\": {\"telemetryKey\": \"telemetryValue\"}\n// }\n\nfunction decodePayload(input) {\n var output = { attributes: {}, telemetry: []};\n \n // --- Decoding code --- //\n var decoded = {};\n for (var i = 0; i < input.length;) {\n var type = input[i++] & 0xff;\n \n if (type == 0x01) { \n // Temperature Converts to °C\n decoded.temperature = parseBytesToInt(input, i, 2, true) / 10;\n i += 2;\n } else if (type == 0x02) { // Humidity\n decoded.humidity = input[i];\n i += 1;\n } else if (type == 0x04) { // Light\n decoded.light = parseBytesToInt(input, i, 2, true);\n i += 2;\n } else if (type == 0x05) { // Pir\n decoded.pir = input[i];\n i += 1;\n } else if (type == 0x06) { // CO₂\n decoded.co2 = parseBytesToInt(input, i, 2, true);\n i += 2;\n } else if (type == 0x07) { // Battery Voltage (VDD)\n decoded.vdd = parseBytesToInt(input, i, 2, true); \n i += 2;\n }\n }\n \n output.telemetry = [{\n ts: timestamp,\n values: decoded\n }];\n\n // --- Decoding code --- //\n return output;\n}\n\n// --- attributes and telemetry objects ---\nvar telemetry = [];\nvar attributes = {};\n// --- attributes and telemetry objects ---\n\n// --- Timestamp parsing\ntimestamp = data.ts;\n// --- Timestamp parsing\n\n// Message parsing\n// To avoid paths in the decoded objects we passing false value to function as \"pathInKey\" argument.\n// Warning: pathInKey can cause already found fields to be overwritten with the last value found.\n\nvar uplinkDataList = [];\n\n// Passing incoming bytes to decodePayload function, to get custom decoding\nvar customDecoding = decodePayload(hexToBytes(data.data));\n\n// Collecting data to result\nif (customDecoding.?telemetry.size() > 0) {\n if (customDecoding.telemetry instanceof java.util.ArrayList) {\n foreach(telemetryObj: customDecoding.telemetry) {\n if (telemetryObj.ts != null && telemetryObj.values != null) {\n telemetry.add(telemetryObj);\n }\n }\n } else {\n telemetry.putAll(customDecoding.telemetry);\n }\n}\n\nif (customDecoding.?attributes.size() > 0) {\n attributes.putAll(customDecoding.attributes);\n}\n\n// You can add some keys manually to attributes or telemetry\nattributes.eui = data.EUI;\nattributes.fPort = data.port;\nattributes.frequency = data.freq;\n\nvar isIncludeGatewayInfo = metadata[\"includeGatewayInfo\"];\nif(isIncludeGatewayInfo == true) {\n var addDataToTelemetry = {};\n addDataToTelemetry.rssi = data.rssi;\n addDataToTelemetry.seqno = data.seqno;\n addDataToTelemetry.snr = data.snr;\n addDataToTelemetry.ack = data.ack;\n addDataToTelemetry.toa = data.toa;\n addDataToTelemetry.fCnt = data.fcnt;\n \n telemetry = processTelemetryData(telemetry, addDataToTelemetry);\n}\n\nvar deviceInfo = {\n deviceName: deviceName,\n deviceType: deviceType,\n// assetName: assetName,\n// assetType: assetType,\n attributes: attributes,\n telemetry: telemetry, \n};\n\naddAdditionalInfoForDeviceMsg(deviceInfo, customerName, groupName);\n\nuplinkDataList.add(deviceInfo);\n\nvar includeGatewayInfo = [\"ts\", \"gweui\", \"rssi\"];\n\nvar gatewayDeviceNamePrefix = \"Gateway \";\nvar gatewayDeviceType = \"Lora gateway\";\nvar gatewayGroupName = null; // If gatewayGroupName is not null - created device will be added to the entity group with such name.\n\nif (data.cmd == \"gw\") {\n foreach( gatewayInfo : data.gws ) {\n var addGatewayInfo = {};\n\n // You can add some keys manually telemetry\n addGatewayInfo.rssi = gatewayInfo.rssi;\n addGatewayInfo.snr = gatewayInfo.snr;\n // You can add some keys manually telemetry\n \n var gatewayInfoMsg = {\n deviceName: gatewayDeviceNamePrefix + gatewayInfo.gweui,\n deviceType: gatewayDeviceType,\n telemetry: [{\n \"ts\": gatewayInfo.ts,\n \"values\": addGatewayInfo\n }],\n attributes: {\n eui: gatewayInfo.gweui\n }\n };\n addAdditionalInfoForDeviceMsg(gatewayInfoMsg, customerName, gatewayGroupName);\n uplinkDataList.add(gatewayInfoMsg);\n }\n}\n\nreturn uplinkDataList;\n\nfunction addAdditionalInfoForDeviceMsg(deviceInfo, customerName, groupName) {\n if (customerName != null) {\n deviceInfo.customerName = customerName;\n }\n if (groupName != null) {\n deviceInfo.groupName = groupName;\n }\n}\n\nfunction processTelemetryData(telemetry, addDataToTelemetry) {\n if (telemetry.size > 1) {\n telemetry = addDataToMultipleTelemetries(telemetry, addDataToTelemetry);\n }\n else if (telemetry.size == 1) {\n telemetry = addDataToSingleTelemetry(telemetry, addDataToTelemetry);\n }\n else {\n telemetry.add(addDataToTelemetry);\n }\n \n return telemetry;\n}\n\nfunction addDataToMultipleTelemetries(telemetry, addDataToTelemetry) {\n foreach(element : addDataToTelemetry.entrySet()) {\n if(!telemetry[0][\"values\"].keys.contains(element.key)) {\n telemetry[0][\"values\"][element.key] = element.value;\n }\n if (!telemetry[1][\"values\"].keys.contains(element.key)) {\n telemetry[1][\"values\"][element.key] = element.value;\n }\n }\n \n return telemetry;\n}\n\nfunction addDataToSingleTelemetry(telemetry, addDataToTelemetry) {\n foreach(element : addDataToTelemetry.entrySet()) {\n if(!telemetry[0][\"values\"].keys.contains(element.key)) {\n telemetry[0][\"values\"][element.key] = element.value;\n }\n }\n \n return telemetry;\n}",
"tbelDecoder": "var data = decodeToJson(payload);\nvar deviceName = \"ERS2 CO2 \" + data.EUI;\nvar deviceType = \"ERS2 CO2\";\nvar groupName = null; // If groupName is not null - created device will be added to the entity group with such name.\nvar customerName = null; // If customerName is not null - created devices will be assigned to customer with such name. \n\n// use assetName and assetType instead of deviceName and deviceType\n// to automatically create assets instead of devices.\n// var assetName = 'Asset A';\n// var assetType = 'building';\n\n// If you want to parse incoming data somehow, you can add your code to this function.\n// input: bytes\n// expected output:\n// {\n// \"attributes\": {\"attributeKey\": \"attributeValue\"},\n// \"telemetry\": {\"telemetryKey\": \"telemetryValue\"}\n// }\n\nfunction decodePayload(input) {\n var output = { attributes: {}, telemetry: []};\n \n // --- Decoding code --- //\n var decoded = {};\n for (var i = 0; i < input.length;) {\n var type = input[i++] & 0xff;\n \n if (type == 0x01) { \n // Temperature Converts to °C\n decoded.temperature = parseBytesToInt(input, i, 2, true) / 10;\n i += 2;\n } else if (type == 0x02) { // Humidity\n decoded.humidity = input[i];\n i += 1;\n } else if (type == 0x04) { // Light\n decoded.light = parseBytesToInt(input, i, 2, true);\n i += 2;\n } else if (type == 0x05) { // Pir\n decoded.pir = input[i];\n i += 1;\n } else if (type == 0x06) { // CO₂\n decoded.co2 = parseBytesToInt(input, i, 2, true);\n i += 2;\n } else if (type == 0x07) { // Battery Voltage (VDD)\n decoded.vdd = parseBytesToInt(input, i, 2, true); \n i += 2;\n }\n }\n \n output.telemetry = [{\n ts: timestamp,\n values: decoded\n }];\n\n // --- Decoding code --- //\n return output;\n}\n\n// --- attributes and telemetry objects ---\nvar telemetry = [];\nvar attributes = {};\n// --- attributes and telemetry objects ---\n\n// --- Timestamp parsing\ntimestamp = data.ts;\n// --- Timestamp parsing\n\n// Message parsing\n// To avoid paths in the decoded objects we passing false value to function as \"pathInKey\" argument.\n// Warning: pathInKey can cause already found fields to be overwritten with the last value found.\n\nvar uplinkDataList = [];\n\n// Passing incoming bytes to decodePayload function, to get custom decoding\nvar customDecoding = decodePayload(hexToBytes(data.data));\n\n// Collecting data to result\nif (customDecoding.?telemetry.size() > 0) {\n if (customDecoding.telemetry instanceof java.util.ArrayList) {\n foreach(telemetryObj: customDecoding.telemetry) {\n if (telemetryObj.ts != null && telemetryObj.values != null) {\n telemetry.add(telemetryObj);\n }\n }\n } else {\n telemetry.putAll(customDecoding.telemetry);\n }\n}\n\nif (customDecoding.?attributes.size() > 0) {\n attributes.putAll(customDecoding.attributes);\n}\n\n// You can add some keys manually to attributes or telemetry\nattributes.eui = data.EUI;\nattributes.fPort = data.port;\nattributes.frequency = data.freq;\n\nvar isIncludeGatewayInfo = metadata[\"includeGatewayInfo\"];\nif(isIncludeGatewayInfo == true) {\n var addDataToTelemetry = {};\n addDataToTelemetry.rssi = data.rssi;\n addDataToTelemetry.seqno = data.seqno;\n addDataToTelemetry.snr = data.snr;\n addDataToTelemetry.ack = data.ack;\n addDataToTelemetry.toa = data.toa;\n addDataToTelemetry.fCnt = data.fcnt;\n \n telemetry = processTelemetryData(telemetry, addDataToTelemetry);\n}\n\nvar deviceInfo = {\n deviceName: deviceName,\n deviceType: deviceType,\n// assetName: assetName,\n// assetType: assetType,\n attributes: attributes,\n telemetry: telemetry, \n};\n\naddAdditionalInfoForDeviceMsg(deviceInfo, customerName, groupName);\n\nuplinkDataList.add(deviceInfo);\n\nvar gatewayDeviceNamePrefix = \"Gateway \";\nvar gatewayDeviceType = \"Lora gateway\";\nvar gatewayGroupName = null; // If gatewayGroupName is not null - created device will be added to the entity group with such name.\n\nif (data.cmd == \"gw\") {\n foreach( gatewayInfo : data.gws ) {\n var addGatewayInfo = {};\n\n // You can add some keys manually telemetry\n addGatewayInfo.rssi = gatewayInfo.rssi;\n addGatewayInfo.snr = gatewayInfo.snr;\n // You can add some keys manually telemetry\n \n var gatewayInfoMsg = {\n deviceName: gatewayDeviceNamePrefix + gatewayInfo.gweui,\n deviceType: gatewayDeviceType,\n telemetry: [{\n \"ts\": gatewayInfo.ts,\n \"values\": addGatewayInfo\n }],\n attributes: {\n eui: gatewayInfo.gweui\n }\n };\n addAdditionalInfoForDeviceMsg(gatewayInfoMsg, customerName, gatewayGroupName);\n uplinkDataList.add(gatewayInfoMsg);\n }\n}\n\nreturn uplinkDataList;\n\nfunction addAdditionalInfoForDeviceMsg(deviceInfo, customerName, groupName) {\n if (customerName != null) {\n deviceInfo.customerName = customerName;\n }\n if (groupName != null) {\n deviceInfo.groupName = groupName;\n }\n}\n\nfunction processTelemetryData(telemetry, addDataToTelemetry) {\n if (telemetry.size > 1) {\n telemetry = addDataToMultipleTelemetries(telemetry, addDataToTelemetry);\n }\n else if (telemetry.size == 1) {\n telemetry = addDataToSingleTelemetry(telemetry, addDataToTelemetry);\n }\n else {\n telemetry.add(addDataToTelemetry);\n }\n \n return telemetry;\n}\n\nfunction addDataToMultipleTelemetries(telemetry, addDataToTelemetry) {\n foreach(element : addDataToTelemetry.entrySet()) {\n if(!telemetry[0][\"values\"].keys.contains(element.key)) {\n telemetry[0][\"values\"][element.key] = element.value;\n }\n if (!telemetry[1][\"values\"].keys.contains(element.key)) {\n telemetry[1][\"values\"][element.key] = element.value;\n }\n }\n \n return telemetry;\n}\n\nfunction addDataToSingleTelemetry(telemetry, addDataToTelemetry) {\n foreach(element : addDataToTelemetry.entrySet()) {\n if(!telemetry[0][\"values\"].keys.contains(element.key)) {\n telemetry[0][\"values\"][element.key] = element.value;\n }\n }\n \n return telemetry;\n}",
"encoder": null,
"tbelEncoder": null,
"updateOnlyKeys": [
Expand Down
32 changes: 32 additions & 0 deletions VENDORS/Elsys/ERS2_CO2/LORIOT/uplink/payload_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"cmd": "gw",
"seqno": 4,
"EUI": "0102030405060708",
"ts": 1690901260493,
"fcnt": 3,
"port": 207,
"freq": 868300000,
"toa": 1319,
"dr": "SF12 BW125 4/5",
"ack": false,
"gws": [
{
"rssi": -38,
"snr": 8.5,
"ts": 1690901260493,
"time": "2023-08-01T14:47:40.493Z",
"gweui": "1020304080706050",
"ant": 0
},
{
"rssi": -42,
"snr": 8.8,
"ts": 1690901260495,
"time": "2023-08-01T14:47:40.495Z",
"gweui": "1020304081716151",
"ant": 0
}
],
"bat": 143,
"data": "0100e202290400270506060308070d62"
}
46 changes: 46 additions & 0 deletions VENDORS/Elsys/ERS2_CO2/LORIOT/uplink/result_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[{
"deviceName": "ERS2 CO2 0102030405060708",
"deviceType": "ERS2 CO2",
"attributes": {
"eui": "0102030405060708",
"fPort": 207,
"frequency": 868300000
},
"telemetry": [{
"ts": 1690901260493,
"values": {
"temperature": 22.6,
"humidity": 41,
"light": 39,
"pir": 6,
"co2": 776,
"vdd": 3426
}
}]
}, {
"deviceName": "Gateway 1020304080706050",
"deviceType": "Lora gateway",
"telemetry": [{
"ts": 1690901260493,
"values": {
"rssi": -38,
"snr": 8.5
}
}],
"attributes": {
"eui": "1020304080706050"
}
}, {
"deviceName": "Gateway 1020304081716151",
"deviceType": "Lora gateway",
"telemetry": [{
"ts": 1690901260495,
"values": {
"rssi": -42,
"snr": 8.8
}
}],
"attributes": {
"eui": "1020304081716151"
}
}]
Loading

0 comments on commit 9530be3

Please sign in to comment.