-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsensecap-data-logger-tripwire.json
434 lines (434 loc) · 26.7 KB
/
sensecap-data-logger-tripwire.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
[
{
"id": "fdfd26c77e5e2a42",
"type": "subflow",
"name": "SenseCAP Data Logger - Tripwire",
"info": "",
"category": "※data-logger-tripwire",
"in": [],
"out": [
{
"x": 2040,
"y": 60,
"wires": [
{
"id": "fbb4b0a21824b98f",
"port": 0
}
]
}
],
"env": [
{
"name": "----- Device Connection ---",
"type": "str",
"value": "",
"ui": {
"type": "none"
}
},
{
"name": "mqttBroker",
"type": "mqtt-broker",
"value": "ff55020100010001",
"ui": {
"icon": "font-awesome/fa-server",
"label": {
"zh-CN": "*Server",
"en-US": "*Server"
},
"type": "conf-types"
}
},
{
"name": "applicationId",
"type": "str",
"value": "447ecfe1-6d26-4e82-bf28-d6dba2fb0d36",
"ui": {
"icon": "font-awesome/fa-align-justify",
"label": {
"zh-CN": "*AppId",
"en-US": "*AppId"
},
"type": "input",
"opts": {
"types": [
"str"
]
}
}
},
{
"name": "deviceId",
"type": "str",
"value": "2cf7f1c0434000e3",
"ui": {
"icon": "font-awesome/fa-align-justify",
"label": {
"zh-CN": "*EUI",
"en-US": "*EUI"
},
"type": "input",
"opts": {
"types": [
"str"
]
}
}
},
{
"name": "----- Output Filter ---",
"type": "str",
"value": "",
"ui": {
"type": "none"
}
},
{
"name": "whenFalseOutput",
"type": "str",
"value": "0",
"ui": {
"label": {
"zh-CN": "if is 0, output:",
"en-US": "if is 0, output:"
},
"type": "input",
"opts": {
"types": [
"str",
"num",
"bool"
]
}
}
},
{
"name": "whenTrueOutput",
"type": "str",
"value": "1",
"ui": {
"label": {
"zh-CN": "if is 1, output:",
"en-US": "if is 1, output:"
},
"type": "input",
"opts": {
"types": [
"str",
"num",
"bool"
]
}
}
}
],
"meta": {},
"color": "#B8EA4F",
"icon": "node-red/node_icon_s2100.png",
"status": {
"x": 2040,
"y": 180,
"wires": [
{
"id": "d6f6d0ab45a73962",
"port": 0
},
{
"id": "statusNode",
"port": 0
}
]
}
},
{
"id": "ddb4e6e006510608",
"type": "mqtt in",
"z": "fdfd26c77e5e2a42",
"name": "subscribe mqtt, and receive message",
"topic": "",
"qos": "0",
"datatype": "auto-detect",
"broker": "${mqttBroker}",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 1,
"x": 690,
"y": 60,
"wires": [
[
"3a8cef5012cb76cd",
"c3ca0d27c2ea2c12"
]
]
},
{
"id": "statusNode",
"type": "status",
"z": "fdfd26c77e5e2a42",
"name": "",
"scope": [
"ddb4e6e006510608"
],
"x": 1870,
"y": 220,
"wires": [
[]
]
},
{
"id": "d39494835463c35e",
"type": "function",
"z": "fdfd26c77e5e2a42",
"name": "build subscribe topic command",
"func": "var applicationId = env.get(\"applicationId\");\nvar deviceId = env.get(\"deviceId\");\n\nif (!applicationId) {\n applicationId = env.get(\"SENSECRAFT_MISSION_PACK_CHIRPSTACK_APPID\");\n}\n\nif (!deviceId) {\n deviceId = env.get(\"SENSECRAFT_MISSION_PACK_DEVICE_TRIPWIRE_DEVEUI\")\n}\n\nmsg.action = 'subscribe'\nmsg.topic = {\n topic: `application/${applicationId}/device/${deviceId}/event/up`,\n qos: 0\n}\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 60,
"wires": [
[
"ddb4e6e006510608"
]
]
},
{
"id": "8b3e99e06e13cf85",
"type": "inject",
"z": "fdfd26c77e5e2a42",
"name": "on startup",
"props": [],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"x": 130,
"y": 60,
"wires": [
[
"d39494835463c35e"
]
]
},
{
"id": "b9d1463ac16b48f1",
"type": "function",
"z": "fdfd26c77e5e2a42",
"d": true,
"name": "decode tripwire message",
"func": "var value = parseInt(msg.payload.object.messages[0][0].measurementValue);\n\nmsg.payload = value;\nmsg.sensecraft = {}\nmsg.sensecraft.fromType = \"Device\"\nmsg.sensecraft.valueMeaning = \"ChangeValue\"\nmsg.sensecraft.valuetype = \"Number\"\nmsg.sensecraft.expectInputType = [\"Condition\"]\n\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1190,
"y": 60,
"wires": [
[
"5da5f4ea1905df1e",
"9a0531c77d01eb12"
]
]
},
{
"id": "3a8cef5012cb76cd",
"type": "change",
"z": "fdfd26c77e5e2a42",
"d": true,
"name": "",
"rules": [
{
"t": "delete",
"p": "topic",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 960,
"y": 60,
"wires": [
[
"b9d1463ac16b48f1"
]
]
},
{
"id": "5da5f4ea1905df1e",
"type": "switch",
"z": "fdfd26c77e5e2a42",
"name": "if value=0, then",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1500,
"y": 40,
"wires": [
[
"a46a241a689227b4"
]
]
},
{
"id": "9a0531c77d01eb12",
"type": "switch",
"z": "fdfd26c77e5e2a42",
"name": "if value=1, then",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1500,
"y": 80,
"wires": [
[
"9d635b7355433cc1"
]
]
},
{
"id": "a46a241a689227b4",
"type": "template",
"z": "fdfd26c77e5e2a42",
"name": "whenFalseOutput",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{env.whenFalseOutput}}",
"output": "str",
"x": 1690,
"y": 40,
"wires": [
[
"fbb4b0a21824b98f"
]
]
},
{
"id": "9d635b7355433cc1",
"type": "template",
"z": "fdfd26c77e5e2a42",
"name": "whenTrueOutput",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{env.whenTrueOutput}}",
"output": "str",
"x": 1690,
"y": 80,
"wires": [
[
"fbb4b0a21824b98f"
]
]
},
{
"id": "fbb4b0a21824b98f",
"type": "function",
"z": "fdfd26c77e5e2a42",
"name": "all in one",
"func": "\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1880,
"y": 60,
"wires": [
[
"d6f6d0ab45a73962"
]
]
},
{
"id": "d6f6d0ab45a73962",
"type": "function",
"z": "fdfd26c77e5e2a42",
"name": "update status",
"func": "return {\n payload: {\n fill: \"green\",\n shape: \"dot\",\n text: 'Last Value: ' + msg.payload\n }\n};",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1880,
"y": 180,
"wires": [
[]
]
},
{
"id": "c3ca0d27c2ea2c12",
"type": "function",
"z": "fdfd26c77e5e2a42",
"name": "decode lorawan raw message",
"func": "// Decode the MQTT payload from ChirpStack, which is Base64 encoded hex data\nvar base64Data = msg.payload.data || \"\";\nvar devEui = msg.payload.deviceInfo.devEui;\nvar bytes = Buffer.from(base64Data, 'base64'); // Decode Base64 string to byte array\nvar port = msg.payload.fPort || 0; // Extract fPort from the message, defaulting to 0 if not present\n\n// Call the decodeUplink function to process the decoded bytes\nmsg = {\n payload: decodeUplink({bytes: bytes}, port).data\n}\n\n// Return the processed message object\nreturn msg;\n\n/**\n * Main decoder function for uplink messages.\n * Takes in the decoded byte array and processes it into a structured format.\n */\nfunction decodeUplink(input, port) {\n var bytes = input['bytes'];\n bytes = bytes2HexString(bytes).toUpperCase(); // Convert byte array to uppercase hex string\n\n let result = {\n 'err': 0, \n 'eui': devEui,\n 'port': port,\n 'payload': bytes, \n 'valid': true,\n 'messages': []\n };\n\n // Split the hex string into individual data frames based on their identifiers\n let splitArray = dataSplit(bytes);\n\n // Decode each data frame according to its dataId and store the results\n let decoderArray = splitArray.map(item => {\n return dataIdAndDataValueJudge(item.dataId, item.dataValue);\n });\n\n // Store the decoded messages in the result object\n result.messages = decoderArray;\n\n return { data: result };\n}\n\n/**\n * Converts a byte array or buffer to a hex string.\n * This function ensures that each byte is represented as a two-character hex value.\n * \n * @param {Buffer|Array} arrBytes - The byte array to convert\n * @returns {string} - The resulting hex string\n */\nfunction bytes2HexString(arrBytes) {\n if (!Array.isArray(arrBytes)) {\n arrBytes = Array.from(arrBytes); // Convert buffer or array-like object to array\n }\n return arrBytes.map(byte => ('0' + (byte & 0xFF).toString(16)).slice(-2)).join('');\n}\n\n/**\n * Splits the hex string into data frames based on their identifiers.\n * Each frame is defined by a dataId and a corresponding dataValue.\n * \n * @param {string} bytes - The hex string to split\n * @returns {Array} - An array of objects containing dataId and dataValue\n */\nfunction dataSplit(bytes) {\n let frameArray = [];\n\n while (bytes.length > 2) {\n let dataId = bytes.substring(0, 2); // Extract the data identifier\n let dataValue;\n let dataObj = {};\n\n // Define the length of each data frame based on the dataId\n const dataIdMap = {\n '01': 22, '20': 22, '21': 22, '30': 22, '31': 22, '33': 22, \n '40': 22, '41': 22, '42': 22, '43': 22, '44': 22, '45': 22,\n '02': 18, '03': 4, '06': 4, '05': 10, '34': 10, \n '04': 20, '10': 20, '32': 20, '35': 20, '36': 20, '37': 20, '38': 20, '39': 20\n };\n\n // Determine the length of the dataValue based on the dataId\n let length = dataIdMap[dataId] || 2;\n dataValue = bytes.substring(2, length); // Extract the dataValue based on the length\n bytes = bytes.substring(length); // Move to the next frame\n\n dataObj = { 'dataId': dataId, 'dataValue': dataValue }; // Create an object for this data frame\n\n frameArray.push(dataObj); // Add the object to the array of frames\n }\n\n return frameArray;\n}\n\n/**\n * Decodes the dataValue of a given dataId and converts it into meaningful measurements.\n * \n * @param {string} dataId - The identifier for the type of data\n * @param {string} dataValue - The hex string representing the data to be decoded\n * @returns {Array} - An array of measurement objects\n */\nfunction dataIdAndDataValueJudge(dataId, dataValue) {\n const measurements = [];\n switch (dataId) {\n case '01': // Temperature, humidity, light intensity, UV index, wind speed\n measurements.push(createMeasurement('4097', 'Air Temperature', dataValue.substring(0, 4), 10));\n measurements.push(createMeasurement('4098', 'Air Humidity', dataValue.substring(4, 6)));\n measurements.push(createMeasurement('4099', 'Light Intensity', dataValue.substring(6, 14)));\n measurements.push(createMeasurement('4190', 'UV Index', dataValue.substring(14, 16), 10));\n measurements.push(createMeasurement('4105', 'Wind Speed', dataValue.substring(16, 20), 10));\n break;\n case '02': // Wind direction, rainfall, barometric pressure\n measurements.push(createMeasurement('4104', 'Wind Direction Sensor', dataValue.substring(0, 4)));\n measurements.push(createMeasurement('4113', 'Rain Gauge', dataValue.substring(4, 12), 1000));\n measurements.push(createMeasurement('4101', 'Barometric Pressure', dataValue.substring(12, 16), 0.1));\n break;\n case '03': // Battery level\n measurements.push({ 'Battery(%)': loraWANV2DataFormat(dataValue) });\n break;\n case '04': // Battery, hardware version, firmware version, measurement intervals\n measurements.push({\n 'Battery(%)': loraWANV2DataFormat(dataValue.substring(0, 2)),\n 'Hardware Version': createVersion(dataValue.substring(2, 6)),\n 'Firmware Version': createVersion(dataValue.substring(6, 10)),\n 'measureInterval': parseInt(loraWANV2DataFormat(dataValue.substring(10, 14))) * 60,\n 'gpsInterval': parseInt(loraWANV2DataFormat(dataValue.substring(14, 18))) * 60\n });\n break;\n case '05': // Measurement interval, GPS interval\n measurements.push({\n 'measureInterval': parseInt(loraWANV2DataFormat(dataValue.substring(0, 4))) * 60,\n 'gpsInterval': parseInt(loraWANV2DataFormat(dataValue.substring(4, 8))) * 60\n });\n break;\n case '06': // Sensor error event\n measurements.push(createErrorMeasurement(dataValue));\n break;\n case '10': // Status and channel type\n let { status, type } = loraWANV2BitDataFormat(dataValue.substring(0, 2));\n measurements.push({\n status: status, \n channelType: type, \n sensorEui: dataValue.substring(2)\n });\n break;\n case '20':\n case '21':\n case '43':\n case '44':\n case '45': // AI detections\n measurements.push(...createAIMeasurements(dataId, dataValue));\n break;\n case '30':\n case '31':\n case '32':\n case '33': // Channel measurements\n measurements.push(...createChannelMeasurements(dataId, dataValue));\n break;\n case '34': // Data logger configuration\n measurements.push({\n 'dataloggerProtocol': loraWANV2DataFormat(dataValue.substring(0, 2)),\n 'dataloggerGPIOInput': loraWANV2DataFormat(dataValue.substring(2, 4)),\n 'dataloggerAnalogType': loraWANV2DataFormat(dataValue.substring(4, 6)),\n 'dataloggerAnalogInterface': loraWANV2DataFormat(dataValue.substring(6, 8))\n });\n break;\n case '35':\n case '36':\n case '37':\n case '38': // Channel pair measurements\n measurements.push(createChannelMeasurementPair(dataValue));\n break;\n case '39': // Battery, hardware version, firmware version, measurement intervals\n measurements.push({\n 'Battery(%)': loraWANV2DataFormat(dataValue.substring(0, 2)),\n 'Hardware Version': createVersion(dataValue.substring(2, 6)),\n 'Firmware Version': createVersion(dataValue.substring(6, 10)),\n 'measureInterval': parseInt(loraWANV2DataFormat(dataValue.substring(10, 14))) * 60,\n 'thresholdMeasureInterval': parseInt(loraWANV2DataFormat(dataValue.substring(14, 18)))\n });\n break;\n case '40':\n case '41': // Light intensity, sound intensity, accelerometer data\n measurements.push(...createSensorMeasurements(dataValue));\n break;\n case '42': // Air temperature, humidity, tVOC, CO2, soil moisture\n measurements.push(createMeasurement('4097', 'Air Temperature', dataValue.substring(0, 4), 100));\n measurements.push(createMeasurement('4098', 'Air Humidity', dataValue.substring(4, 8), 100));\n measurements.push(createMeasurement('4195', 'Total Volatile Organic Compounds', dataValue.substring(8, 12)));\n measurements.push(createMeasurement('4100', 'CO2', dataValue.substring(12, 16)));\n measurements.push(createMeasurement('4196', 'Soil moisture intensity', dataValue.substring(16, 20)));\n break;\n default:\n break;\n }\n return measurements;\n}\n\n/**\n * Creates a measurement object.\n * \n * @param {string} measurementId - The ID of the measurement type\n * @param {string} type - The type of measurement (e.g., temperature, humidity)\n * @param {string} data - The raw hex string representing the data\n * @param {number} divisor - A divisor for scaling the data value (optional)\n * @returns {Object} - A measurement object with the formatted data\n */\nfunction createMeasurement(measurementId, type, data, divisor = 1) {\n return {\n measurementValue: loraWANV2DataFormat(data, divisor),\n measurementId: measurementId,\n type: type\n };\n}\n\n/**\n * Creates a version string from a data string.\n * \n * @param {string} data - The raw hex string representing version information\n * @returns {string} - The formatted version string (e.g., \"1.0\")\n */\nfunction createVersion(data) {\n return `${loraWANV2DataFormat(data.substring(0, 2))}.${loraWANV2DataFormat(data.substring(2, 4))}`;\n}\n\n/**\n * Creates an error measurement object based on an error code.\n * \n * @param {string} dataValue - The raw hex string representing the error code\n * @returns {Object} - An error measurement object with detailed error information\n */\nfunction createErrorMeasurement(dataValue) {\n const errorCodes = {\n '00': 'CCL_SENSOR_ERROR_NONE',\n '01': 'CCL_SENSOR_NOT_FOUND',\n '02': 'CCL_SENSOR_WAKEUP_ERROR',\n '03': 'CCL_SENSOR_NOT_RESPONSE',\n '04': 'CCL_SENSOR_DATA_EMPTY',\n '05': 'CCL_SENSOR_DATA_HEAD_ERROR',\n '06': 'CCL_SENSOR_DATA_CRC_ERROR',\n '07': 'CCL_SENSOR_DATA_B1_NO_VALID',\n '08': 'CCL_SENSOR_DATA_B2_NO_VALID',\n '09': 'CCL_SENSOR_RANDOM_NOT_MATCH',\n '0A': 'CCL_SENSOR_PUBKEY_SIGN_VERIFY_FAILED',\n '0B': 'CCL_SENSOR_DATA_SIGN_VERIFY_FAILED',\n '0C': 'CCL_SENSOR_DATA_VALUE_HI',\n '0D': 'CCL_SENSOR_DATA_VALUE_LOW',\n '0E': 'CCL_SENSOR_DATA_VALUE_MISSED',\n '0F': 'CCL_SENSOR_ARG_INVAILD',\n '10': 'CCL_SENSOR_RS485_MASTER_BUSY',\n '11': 'CCL_SENSOR_RS485_REV_DATA_ERROR',\n '12': 'CCL_SENSOR_RS485_REG MISSING',\n '13': 'CCL_SENSOR_RS485_FUN_EXE_ERROR',\n '14': 'CCL_SENSOR_RS485_WRITE_STRATEGY_ERROR',\n '15': 'CCL_SENSOR_CONFIG_ERROR',\n 'FF': 'CCL_SENSOR_DATA_ERROR_UNKNOWN'\n };\n const errCode = dataValue;\n return {\n measurementId: '4101',\n type: 'sensor_error_event',\n errCode: errCode,\n descZh: errorCodes[errCode] || 'CC_OTHER_FAILED'\n };\n}\n\n/**\n * Creates an array of AI detection measurements.\n * \n * @param {string} dataId - The identifier for the AI detection type\n * @param {string} dataValue - The raw hex string representing AI detection data\n * @returns {Array} - An array of AI detection measurement objects\n */\nfunction createAIMeasurements(dataId, dataValue) {\n let measurements = [];\n let initMeasurementId = dataId === '20' ? 4175 : dataId === '21' ? 4180 : 0;\n for (let i = 0; i < dataValue.length; i += 4) {\n let modelId = loraWANV2DataFormat(dataValue.substring(i, i + 2));\n let detectionType = loraWANV2DataFormat(dataValue.substring(i + 2, i + 4));\n let aiValues = `${modelId}.${detectionType}`;\n measurements.push({\n measurementValue: aiValues,\n measurementId: initMeasurementId,\n type: `AI Detection ${i}`\n });\n initMeasurementId++;\n }\n return measurements;\n}\n\n/**\n * Creates an array of channel measurements.\n * \n * @param {string} dataId - The identifier for the channel measurement type\n * @param {string} dataValue - The raw hex string representing channel measurement data\n * @returns {Array} - An array of channel measurement objects\n */\nfunction createChannelMeasurements(dataId, dataValue) {\n let measurements = [];\n let channelInfo = loraWANV2ChannelBitFormat(dataValue.substring(0, 2));\n let dataOne = createMeasurement(parseInt(channelInfo.one), 'Measurement', dataValue.substring(4, 12), 1000);\n let dataTwo = createMeasurement(parseInt(channelInfo.two), 'Measurement', dataValue.substring(12, 20), 1000);\n\n if (parseInt(channelInfo.one)) measurements.push(dataOne);\n if (parseInt(channelInfo.two)) measurements.push(dataTwo);\n return measurements;\n}\n\n/**\n * Creates a pair of channel measurement objects.\n * \n * @param {string} dataValue - The raw hex string representing the channel data\n * @returns {Object} - An object containing two channel measurements\n */\nfunction createChannelMeasurementPair(dataValue) {\n let channelInfo = loraWANV2ChannelBitFormat(dataValue.substring(0, 2));\n let channelSortOne = 3920 + (parseInt(channelInfo.one) - 1) * 2;\n let channelSortTwo = 3921 + (parseInt(channelInfo.two) - 1) * 2;\n\n return {\n [channelSortOne]: loraWANV2DataFormat(dataValue.substring(2, 10), 1000),\n [channelSortTwo]: loraWANV2DataFormat(dataValue.substring(10, 18), 1000)\n };\n}\n\n/**\n * Creates an array of sensor measurements (light intensity, sound intensity, accelerometer data).\n * \n * @param {string} dataValue - The raw hex string representing sensor data\n * @returns {Array} - An array of sensor measurement objects\n */\nfunction createSensorMeasurements(dataValue) {\n return [\n createMeasurement('4193', 'Light Intensity', dataValue.substring(0, 4)),\n createMeasurement('4192', 'Sound Intensity', dataValue.substring(4, 8)),\n createMeasurement('4150', 'AccelerometerX', dataValue.substring(8, 12), 100),\n createMeasurement('4151', 'AccelerometerY', dataValue.substring(12, 16), 100),\n createMeasurement('4152', 'AccelerometerZ', dataValue.substring(16, 20), 100)\n ];\n}\n\n/**\n * Converts a hex string to a decimal number, applying a divisor for scaling if necessary.\n * Handles big-endian formats and supports signed integers.\n * \n * @param {string} str - The raw hex string to format\n * @param {number} divisor - A divisor for scaling the result (optional, default is 1)\n * @returns {number} - The formatted value as a number\n */\nfunction loraWANV2DataFormat(str, divisor = 1) {\n let strReverse = bigEndianTransform(str);\n let str2 = toBinary(strReverse);\n if (str2[0] === '1') {\n let arr = str2.split('').map(item => (parseInt(item) === 1 ? 0 : 1));\n str2 = parseInt(arr.join(''), 2) + 1;\n return -str2 / divisor;\n }\n return parseInt(str2, 2) / divisor;\n}\n\n/**\n * Transforms a hex string from big-endian format to an array of bytes.\n * \n * @param {string} data - The raw hex string\n * @returns {Array} - An array of byte strings\n */\nfunction bigEndianTransform(data) {\n let dataArray = [];\n for (let i = 0; i < data.length; i += 2) {\n dataArray.push(data.substring(i, i + 2));\n }\n return dataArray;\n}\n\n/**\n * Converts an array of hex bytes to a binary string.\n * Ensures each byte is represented as an 8-bit binary number.\n * \n * @param {Array} arr - The array of hex byte strings\n * @returns {string} - The concatenated binary string\n */\nfunction toBinary(arr) {\n return arr.map(item => parseInt(item, 16).toString(2).padStart(8, '0')).join('');\n}\n\n/**\n * Decodes a status and channel type from a bitfield.\n * \n * @param {string} str - The raw hex string representing the bitfield\n * @returns {Object} - An object containing the decoded channel, status, and type\n */\nfunction loraWANV2BitDataFormat(str) {\n let strReverse = bigEndianTransform(str);\n let str2 = toBinary(strReverse);\n return {\n channel: parseInt(str2.substring(0, 4), 2),\n status: parseInt(str2.substring(4, 5), 2),\n type: parseInt(str2.substring(5), 2)\n };\n}\n\n/**\n * Decodes two channel identifiers from a bitfield.\n * \n * @param {string} str - The raw hex string representing the bitfield\n * @returns {Object} - An object containing the decoded channel identifiers\n */\nfunction loraWANV2ChannelBitFormat(str) {\n let strReverse = bigEndianTransform(str);\n let str2 = toBinary(strReverse);\n return {\n one: parseInt(str2.substring(0, 4), 2),\n two: parseInt(str2.substring(4, 8), 2)\n };\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 990,
"y": 180,
"wires": [
[
"6f15162a393a1c41"
]
]
},
{
"id": "6f15162a393a1c41",
"type": "function",
"z": "fdfd26c77e5e2a42",
"name": "decode tripwire message",
"func": "var value = parseInt(msg.payload.messages[0][0].measurementValue);\n\nreturn {\n payload: value,\n sensecraft: {\n fromType: 'Device',\n valueMeaning: 'ChangeValue',\n valuetype: 'Number',\n expectInputType: ['Condition']\n }\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1270,
"y": 180,
"wires": [
[
"5da5f4ea1905df1e",
"9a0531c77d01eb12"
]
]
}
]