Skip to content

Commit

Permalink
Merge pull request #70 from artem-barysh-dev/r718h
Browse files Browse the repository at this point in the history
R718H
  • Loading branch information
ashvayka authored Nov 26, 2024
2 parents 1b1c49c + 7798007 commit fcc7ca5
Show file tree
Hide file tree
Showing 35 changed files with 1,089 additions and 0 deletions.
36 changes: 36 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/converter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "ChirpStack Uplink Decoder for R718H",
"type": "UPLINK",
"debugMode": true,
"configuration": {
"scriptLang": "TBEL",
"decoder": null,
"tbelDecoder": "var data = decodeToJson(payload);\nvar deviceName = data.deviceInfo.deviceName + \" \" + data.deviceInfo.devEui;\nvar deviceType = \"R718H\";\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\": [{\"ts\": 1...1, \"values\": {\"telemetryKey\":\"telemetryValue\"}, {\"ts\": 1...2, \"values\": {\"telemetryKey\":\"telemetryValue\"}}]\n// }\n\nfunction decodePayload(input) {\n var output = {\n attributes: {},\n telemetry: []\n };\n \n // --- Decoding code --- //\n var fPort = data.fPort;\n var decoded = {};\n if(fPort == 6) {\n if(input[1] == 0x1F && input[2] == 0x01) {\n decoded.battery_voltage = parseBytesToInt(input, 3, 1) / 10;\n decoded.pulseCount = parseBytesToInt(input, 4, 2);\n }\n if(input[1] == 0x1F && input[2] == 0x00) {\n output.attributes.softwareVersion = input[3] / 10;\n output.attributes.hardwareVersion = input[4];\n output.attributes.dateCode = decodeDateCodeToTimestamp(java.util.Arrays.copyOfRange(input, 5, 9));\n }\n }\n if(fPort == 7) {\n if(input[1] == 0x1F && (input[0] & 0xff) == 0x81) {\n decoded.cmd = \"configReportRsp\";\n decoded.status = input[2] == 0x00 ? \"success\" : \"failure\";\n }\n if(input[1] == 0x1F && (input[0] & 0xff) == 0x82) {\n decoded.cmd = \"readConfigReportRsp\";\n decoded.minTime = parseBytesToInt(input, 2, 2);\n decoded.maxTime = parseBytesToInt(input, 4, 2);\n decoded.batteryChange = parseBytesToInt(input, 6, 1) / 10;\n }\n if(input[1] == 0x1F && (input[0] & 0xff) == 0x83) {\n decoded.cmd = \"setFiltertimeRsp\";\n decoded.status = input[2] == 0x00 ? \"success\" : \"failure\";\n }\n if(input[1] == 0x1F && (input[0] & 0xff) == 0x84) {\n decoded.cmd = \"getFiltertimeReq\";\n decoded.filterTime = input[2] * 5;\n }\n if(input[1] == 0x1F && (input[0] & 0xff) == 0x85) {\n decoded.cmd = \"setPulseCounterClearModeRsp\";\n decoded.status = input[2] == 0x00 ? \"success\" : \"failure\";\n }\n if(input[1] == 0x1F && (input[0] & 0xff) == 0x86) {\n decoded.cmd = \"getPulseCounterClearModeRsp\";\n decoded.pulse_counter_clear_mode = input[2] == 0x00 ? \"clear when send\" : \"clear when roll-over\";\n }\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\nvar dateString = data.time;\ntimestamp = parseDateToTimestamp(dateString);\n// --- Timestamp parsing\n\n// Passing incoming bytes to decodePayload function, to get custom decoding\nvar customDecoding = decodePayload(base64ToBytes(data.data));\n\n\nattributes.eui = data.deviceInfo.devEui;\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.deviceInfo.?devEui;\nattributes.devAddr = data.devAddr;\nattributes.fPort = data.fPort;\nattributes.applicationId = data.deviceInfo.?applicationId;\nattributes.applicationName = data.deviceInfo.?applicationName;\nattributes.tenantId = data.deviceInfo.?tenantId;\nattributes.tenantName = data.deviceInfo.?tenantName;\nattributes.deviceProfileId = data.deviceInfo.?deviceProfileId;\nattributes.deviceProfileName = data.deviceInfo.?deviceProfileName;\nattributes.frequency = data.txInfo.?frequency;\nattributes.bandwidth = data.txInfo.?modulation.?lora.?bandwidth;\nattributes.spreadingFactor = data.txInfo.?modulation.?lora.?spreadingFactor;\nattributes.codeRate = data.txInfo.?modulation.?lora.?codeRate;\n\nif(Boolean.parseBoolean(metadata[\"includeGatewayInfo\"])) {\n var gatewayInfo = getGatewayInfo();\n var addDataToTelemetry = {};\n addDataToTelemetry.snr = gatewayInfo.snr;\n addDataToTelemetry.rssi = gatewayInfo.rssi;\n addDataToTelemetry.channel = gatewayInfo.channel;\n addDataToTelemetry.rfChain = gatewayInfo.rfChain;\n addDataToTelemetry.fCnt = data.fCnt;\n \n telemetry = processTelemetryData(telemetry, addDataToTelemetry);\n}\n\nvar result = {\n deviceName: deviceName,\n deviceType: deviceType,\n // assetName: assetName,\n // assetType: assetType,\n attributes: attributes,\n telemetry: telemetry\n};\n\naddAdditionalInfoForDeviceMsg(result, customerName, groupName);\n\nreturn result;\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 parseDateToTimestamp(dateString) {\n var timestamp = -1;\n if (dateString != null) {\n timestamp = new Date(dateString).getTime();\n if (timestamp == -1) {\n var secondsSeparatorIndex = dateString.lastIndexOf(\n '.') + 1;\n var millisecondsEndIndex = dateString.lastIndexOf(\n '+');\n if (millisecondsEndIndex == -1) {\n millisecondsEndIndex = dateString.lastIndexOf(\n 'Z');\n }\n if (millisecondsEndIndex == -1) {\n millisecondsEndIndex = dateString.lastIndexOf(\n '-');\n }\n if (millisecondsEndIndex == -1) {\n if (dateString.length >= secondsSeparatorIndex +\n 3) {\n dateString = dateString.substring(0,\n secondsSeparatorIndex + 3);\n }\n } else {\n dateString = dateString.substring(0,\n secondsSeparatorIndex + 3) +\n dateString.substring(millisecondsEndIndex,\n dateString.length);\n }\n timestamp = new Date(dateString).getTime();\n }\n }\n // If we cannot parse timestamp - we will use the current timestamp\n if (timestamp == -1) {\n timestamp = Date.now();\n }\n \n return timestamp;\n}\n\nfunction getGatewayInfo() {\n var gatewayList = data.rxInfo;\n var maxRssi = Integer.MIN_VALUE;\n var gatewayInfo = {};\n \n foreach (gateway : gatewayList) {\n if(gateway.rssi > maxRssi) {\n maxRssi = gateway.rssi;\n gatewayInfo = gateway;\n }\n }\n \n return gatewayInfo;\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}\n\nfunction decodeDateCodeToTimestamp(bytes) {\n var hexString = \"\";\n for (b : bytes) {\n hexString += String.format(\"%02X\", b);\n }\n \n var yearString = hexString.substring(0, 4);\n var monthString = hexString.substring(4, 6);\n var dayString = hexString.substring(6, 8);\n \n var year = Integer.parseInt(yearString);\n var month = Integer.parseInt(monthString); \n var day = Integer.parseInt(dayString);\n \n var dateDateCode = new Date(year, month, day);\n var timestampDateCode = dateDateCode.getTime();\n \n return timestampDateCode;\n}",
"encoder": null,
"tbelEncoder": null,
"updateOnlyKeys": [
"tenantId",
"tenantName",
"applicationId",
"applicationName",
"deviceProfileId",
"deviceProfileName",
"devAddr",
"fPort",
"frequency",
"bandwidth",
"spreadingFactor",
"codeRate",
"channel",
"rfChain",
"eui",
"battery_voltage",
"softwareVersion",
"hardwareVersion"
]
},
"additionalInfo": {
"description": ""
},
"edgeTemplate": false
}
4 changes: 4 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"integrationName": "ChirpStack integration",
"includeGatewayInfo": "false"
}
48 changes: 48 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"deduplicationId": "57433366-50a6-4dc2-8145-2df1bbc70d9e",
"time": "2023-05-22T07:47:05.404859+00:00",
"deviceInfo": {
"tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
"tenantName": "ChirpStack",
"applicationId": "ca739e26-7b67-4f14-b69e-d568c22a5a75",
"applicationName": "Chirpstack application",
"deviceProfileId": "605d08d4-65f5-4d2c-8a5a-3d2457662f79",
"deviceProfileName": "Chirpstack default device profile",
"deviceName": "Device name",
"devEui": "1000000000000001",
"tags": {}
},
"devAddr": "20000001",
"adr": true,
"dr": 5,
"fCnt": 4,
"fPort": 6,
"confirmed": false,
"data": "AR8BJADIAAAAAAA=",
"rxInfo": [{
"gatewayId": "6a7e111a10000000",
"uplinkId": 24022,
"time": "2023-05-22T07:47:05.404859+00:00",
"rssi": -35,
"snr": 11.5,
"channel": 2,
"rfChain": 1,
"location": {},
"context": "EFwMtA==",
"metadata": {
"region_common_name": "EU868",
"region_config_id": "eu868"
},
"crcStatus": "CRC_OK"
}],
"txInfo": {
"frequency": 868500000,
"modulation": {
"lora": {
"bandwidth": 125000,
"spreadingFactor": 7,
"codeRate": "CR_4_5"
}
}
}
}
48 changes: 48 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/payload_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"deduplicationId": "57433366-50a6-4dc2-8145-2df1bbc70d9e",
"time": "2023-05-22T07:47:05.404859+00:00",
"deviceInfo": {
"tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
"tenantName": "ChirpStack",
"applicationId": "ca739e26-7b67-4f14-b69e-d568c22a5a75",
"applicationName": "Chirpstack application",
"deviceProfileId": "605d08d4-65f5-4d2c-8a5a-3d2457662f79",
"deviceProfileName": "Chirpstack default device profile",
"deviceName": "Device name",
"devEui": "1000000000000001",
"tags": {}
},
"devAddr": "20000001",
"adr": true,
"dr": 5,
"fCnt": 4,
"fPort": 7,
"confirmed": false,
"data": "gR8BAAAAAAAAAAA=",
"rxInfo": [{
"gatewayId": "6a7e111a10000000",
"uplinkId": 24022,
"time": "2023-05-22T07:47:05.404859+00:00",
"rssi": -35,
"snr": 11.5,
"channel": 2,
"rfChain": 1,
"location": {},
"context": "EFwMtA==",
"metadata": {
"region_common_name": "EU868",
"region_config_id": "eu868"
},
"crcStatus": "CRC_OK"
}],
"txInfo": {
"frequency": 868500000,
"modulation": {
"lora": {
"bandwidth": 125000,
"spreadingFactor": 7,
"codeRate": "CR_4_5"
}
}
}
}
48 changes: 48 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/payload_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"deduplicationId": "57433366-50a6-4dc2-8145-2df1bbc70d9e",
"time": "2023-05-22T07:47:05.404859+00:00",
"deviceInfo": {
"tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
"tenantName": "ChirpStack",
"applicationId": "ca739e26-7b67-4f14-b69e-d568c22a5a75",
"applicationName": "Chirpstack application",
"deviceProfileId": "605d08d4-65f5-4d2c-8a5a-3d2457662f79",
"deviceProfileName": "Chirpstack default device profile",
"deviceName": "Device name",
"devEui": "1000000000000001",
"tags": {}
},
"devAddr": "20000001",
"adr": true,
"dr": 5,
"fCnt": 4,
"fPort": 7,
"confirmed": false,
"data": "hh8BAAAAAAAAAAA=",
"rxInfo": [{
"gatewayId": "6a7e111a10000000",
"uplinkId": 24022,
"time": "2023-05-22T07:47:05.404859+00:00",
"rssi": -35,
"snr": 11.5,
"channel": 2,
"rfChain": 1,
"location": {},
"context": "EFwMtA==",
"metadata": {
"region_common_name": "EU868",
"region_config_id": "eu868"
},
"crcStatus": "CRC_OK"
}],
"txInfo": {
"frequency": 868500000,
"modulation": {
"lora": {
"bandwidth": 125000,
"spreadingFactor": 7,
"codeRate": "CR_4_5"
}
}
}
}
26 changes: 26 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"deviceName": "Device name 1000000000000001",
"deviceType": "R718H",
"attributes": {
"eui": "1000000000000001",
"devAddr": "20000001",
"fPort": 6,
"applicationId": "ca739e26-7b67-4f14-b69e-d568c22a5a75",
"applicationName": "Chirpstack application",
"tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
"tenantName": "ChirpStack",
"deviceProfileId": "605d08d4-65f5-4d2c-8a5a-3d2457662f79",
"deviceProfileName": "Chirpstack default device profile",
"frequency": 868500000,
"bandwidth": 125000,
"spreadingFactor": 7,
"codeRate": "CR_4_5"
},
"telemetry": [{
"ts": 1684741625404,
"values": {
"battery_voltage": 3.6,
"pulseCount": 200
}
}]
}
26 changes: 26 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/result_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"deviceName": "Device name 1000000000000001",
"deviceType": "R718H",
"attributes": {
"eui": "1000000000000001",
"devAddr": "20000001",
"fPort": 7,
"applicationId": "ca739e26-7b67-4f14-b69e-d568c22a5a75",
"applicationName": "Chirpstack application",
"tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
"tenantName": "ChirpStack",
"deviceProfileId": "605d08d4-65f5-4d2c-8a5a-3d2457662f79",
"deviceProfileName": "Chirpstack default device profile",
"frequency": 868500000,
"bandwidth": 125000,
"spreadingFactor": 7,
"codeRate": "CR_4_5"
},
"telemetry": [{
"ts": 1684741625404,
"values": {
"cmd": "configReportRsp",
"status": "failure"
}
}]
}
26 changes: 26 additions & 0 deletions VENDORS/Netvox/R718H/ChirpStack/uplink/result_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"deviceName": "Device name 1000000000000001",
"deviceType": "R718H",
"attributes": {
"eui": "1000000000000001",
"devAddr": "20000001",
"fPort": 7,
"applicationId": "ca739e26-7b67-4f14-b69e-d568c22a5a75",
"applicationName": "Chirpstack application",
"tenantId": "52f14cd4-c6f1-4fbd-8f87-4025e1d49242",
"tenantName": "ChirpStack",
"deviceProfileId": "605d08d4-65f5-4d2c-8a5a-3d2457662f79",
"deviceProfileName": "Chirpstack default device profile",
"frequency": 868500000,
"bandwidth": 125000,
"spreadingFactor": 7,
"codeRate": "CR_4_5"
},
"telemetry": [{
"ts": 1684741625404,
"values": {
"cmd": "getPulseCounterClearModeRsp",
"pulse_counter_clear_mode": "clear when roll-over"
}
}]
}
Loading

0 comments on commit fcc7ca5

Please sign in to comment.