-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDL-PAR.Docksters.json
30 lines (30 loc) · 3.07 KB
/
DL-PAR.Docksters.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
"createdUTC": "2020-05-29T18:06:30.651Z",
"definitionIsPublic": false,
"definitionName": "DL-PAR",
"displayName": "DL-PAR Photosynthetically Active Radiation Sensor for LoRaWAN®",
"manufacturer": "Decentlab",
"organizationId": "9f014719-4add-4989-ba0f-fc7edc44d893",
"parser": "\n/* https://www.decentlab.com/products/photosynthetically-active-radiation-sensor-for-lorawan */\n\nvar decentlab_decoder = {\n PROTOCOL_VERSION: 2,\n SENSORS: [\n {length: 1,\n values: [{name: 'photosynthetically_active_radiation',\n displayName: 'Photosynthetically active radiation',\n convert: function (x) { return 3 * (x[0] / 32768 - 1) * 1000 * 5; },\n unit: 'µmol⋅m⁻²⋅s⁻¹'}]},\n {length: 1,\n values: [{name: 'battery_voltage',\n displayName: 'Battery voltage',\n convert: function (x) { return x[0] / 1000; },\n unit: 'V'}]}\n ],\n\n read_int: function (bytes, pos) {\n return (bytes[pos] << 8) + bytes[pos + 1];\n },\n\n decode: function (msg) {\n var bytes = msg;\n var i, j;\n if (typeof msg === 'string') {\n bytes = [];\n for (i = 0; i < msg.length; i += 2) {\n bytes.push(parseInt(msg.substring(i, i + 2), 16));\n }\n }\n\n var version = bytes[0];\n if (version != this.PROTOCOL_VERSION) {\n return {error: \"protocol version \" + version + \" doesn't match v2\"};\n }\n\n var deviceId = this.read_int(bytes, 1);\n var flags = this.read_int(bytes, 3);\n var result = {'protocol_version': version, 'device_id': deviceId};\n // decode payload\n var pos = 5;\n for (i = 0; i < this.SENSORS.length; i++, flags >>= 1) {\n if ((flags & 1) !== 1)\n continue;\n\n var sensor = this.SENSORS[i];\n var x = [];\n // convert data to 16-bit integer array\n for (j = 0; j < sensor.length; j++) {\n x.push(this.read_int(bytes, pos));\n pos += 2;\n }\n\n // decode sensor values\n for (j = 0; j < sensor.values.length; j++) {\n var value = sensor.values[j];\n if ('convert' in value) {\n result[value.name] = {displayName: value.displayName,\n value: value.convert.bind(this)(x)};\n if ('unit' in value)\n result[value.name]['unit'] = value.unit;\n }\n }\n }\n return result;\n }\n};\n\nfunction parsePayload(payload) {\n var decoded = decentlab_decoder.decode(payload);\n Object.keys(decoded).map(function(key, index) { decoded[key] = decoded[key]['value'];});\n return decoded;\n}",
"sensors": [
{
"name": "photosynthetically_active_radiation",
"displayName": "Photosynthetically active radiation /µmol⋅m⁻²⋅s⁻¹/",
"type": "float"
},
{
"displayName": "Battery voltage",
"name": "battery_voltage",
"thresholds": [
{
"name": "Battery voltage is low",
"type": "lessthan",
"warning": "2.2"
}
],
"type": "volts"
}
],
"updatedUTC": "2020-05-29T18:06:30.651Z",
"version": "v1.0"
}