@ncd-io/node-red-enterprise-sensors 1.6.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/WirelessGateway.js +2342 -3011
- package/lib/sensors/1.js +215 -0
- package/lib/sensors/103.js +1024 -0
- package/lib/sensors/114.js +1342 -0
- package/lib/sensors/125.js +619 -0
- package/lib/sensors/126.js +680 -0
- package/lib/utils.js +27 -0
- package/package.json +4 -1
- package/wireless.html +431 -82
- package/wireless.js +820 -219
package/lib/sensors/1.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
const { toMac, signInt, msbLsb } = require('../utils');
|
|
2
|
+
|
|
3
|
+
// --- 1. DEFINE LOCAL FUNCTIONS ---
|
|
4
|
+
// These are defined as local variables so they can call each other easily.
|
|
5
|
+
module.exports = (globalDevices) => {
|
|
6
|
+
|
|
7
|
+
const get_write_buffer_size = (firmware) => {
|
|
8
|
+
return 14;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const get_config_map = (firmware) => {
|
|
12
|
+
console.log('Generating sync map for firmware version', firmware);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
"core_version": {
|
|
16
|
+
"read_index": 3,
|
|
17
|
+
"descriptions": {
|
|
18
|
+
"title": "Core Version",
|
|
19
|
+
"main_caption": "The version of the core communication stack."
|
|
20
|
+
},
|
|
21
|
+
"validator": {
|
|
22
|
+
"type": "uint8"
|
|
23
|
+
},
|
|
24
|
+
"tags": [
|
|
25
|
+
"system"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"firmware_version": {
|
|
29
|
+
"read_index": 4,
|
|
30
|
+
"descriptions": {
|
|
31
|
+
"title": "Firmware Version",
|
|
32
|
+
"main_caption": "The application-specific firmware version."
|
|
33
|
+
},
|
|
34
|
+
"validator": {
|
|
35
|
+
"type": "uint8"
|
|
36
|
+
},
|
|
37
|
+
"tags": [
|
|
38
|
+
"system"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"sensor_type": {
|
|
42
|
+
"read_index": 5,
|
|
43
|
+
"descriptions": {
|
|
44
|
+
"title": "Sensor Type",
|
|
45
|
+
"main_caption": "The hardware identifier for the specific sensor model."
|
|
46
|
+
},
|
|
47
|
+
"validator": {
|
|
48
|
+
"type": "uint16be"
|
|
49
|
+
},
|
|
50
|
+
"tags": [
|
|
51
|
+
"system"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"tx_lifetime_counter": {
|
|
55
|
+
"read_index": 7,
|
|
56
|
+
"descriptions": {
|
|
57
|
+
"title": "Sampling Interval",
|
|
58
|
+
"main_caption": "Set how often will the sensor transmit measurement data. Note: For this sensor, this value functions as the sampling interval rather than a traditional delay.",
|
|
59
|
+
"sub_caption": "Default value: 20 milliseconds."
|
|
60
|
+
},
|
|
61
|
+
"validator": {
|
|
62
|
+
"type": "uint32be"
|
|
63
|
+
},
|
|
64
|
+
"tags": [
|
|
65
|
+
"diagnostics"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"hardware_id": {
|
|
69
|
+
"read_index": 11,
|
|
70
|
+
"length": 3,
|
|
71
|
+
"descriptions": {
|
|
72
|
+
"title": "Hardware ID",
|
|
73
|
+
"main_caption": "A unique 3-byte hardware identifier."
|
|
74
|
+
},
|
|
75
|
+
"validator": {
|
|
76
|
+
"type": "buffer"
|
|
77
|
+
},
|
|
78
|
+
"tags": [
|
|
79
|
+
"system"
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"network_id": {
|
|
83
|
+
"read_index": 14,
|
|
84
|
+
"write_index": 3,
|
|
85
|
+
"length": 2,
|
|
86
|
+
"descriptions": {
|
|
87
|
+
"title": "Network ID",
|
|
88
|
+
"main_caption": ""
|
|
89
|
+
},
|
|
90
|
+
"default_value": "7fff",
|
|
91
|
+
"validator": {
|
|
92
|
+
"type": "hex",
|
|
93
|
+
"length": 4
|
|
94
|
+
},
|
|
95
|
+
"html_id": "pan_id",
|
|
96
|
+
"tags": [
|
|
97
|
+
"communications"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
"destination_address": {
|
|
101
|
+
"read_index": 16,
|
|
102
|
+
"write_index": 5,
|
|
103
|
+
"length": 4,
|
|
104
|
+
"descriptions": {
|
|
105
|
+
"title": "Destination Address",
|
|
106
|
+
"main_caption": ""
|
|
107
|
+
},
|
|
108
|
+
"default_value": "0000ffff",
|
|
109
|
+
"validator": {
|
|
110
|
+
"type": "mac",
|
|
111
|
+
"length": 8
|
|
112
|
+
},
|
|
113
|
+
"html_id": "destination",
|
|
114
|
+
"tags": [
|
|
115
|
+
"communications"
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
"node_id": {
|
|
119
|
+
"read_index": 20,
|
|
120
|
+
"write_index": 9,
|
|
121
|
+
"descriptions": {
|
|
122
|
+
"title": "Node ID",
|
|
123
|
+
"main_caption": ""
|
|
124
|
+
},
|
|
125
|
+
"default_value": "0",
|
|
126
|
+
"validator": {
|
|
127
|
+
"type": "uint8",
|
|
128
|
+
"min": 0,
|
|
129
|
+
"max": 255,
|
|
130
|
+
"generated": true
|
|
131
|
+
},
|
|
132
|
+
"html_id": "node_id",
|
|
133
|
+
"tags": [
|
|
134
|
+
"generic"
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
"report_rate": {
|
|
138
|
+
"read_index": 21,
|
|
139
|
+
"write_index": 10,
|
|
140
|
+
"descriptions": {
|
|
141
|
+
"title": "Delay",
|
|
142
|
+
"main_caption": ""
|
|
143
|
+
},
|
|
144
|
+
"default_value": 3,
|
|
145
|
+
"validator": {
|
|
146
|
+
"type": "uint32be"
|
|
147
|
+
},
|
|
148
|
+
"html_id": "delay"
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const sync_parse = (rep_buffer) => {
|
|
154
|
+
let response = {};
|
|
155
|
+
|
|
156
|
+
// Get the map based on the sensor type byte
|
|
157
|
+
const sync_map = get_config_map(rep_buffer[4]);
|
|
158
|
+
|
|
159
|
+
for (const [key, config] of Object.entries(sync_map)) {
|
|
160
|
+
// Destructure 'type' from inside 'validator' and rename 'read_index' to 'idx'
|
|
161
|
+
const { read_index: idx, length, validator: { type } = {} } = config;
|
|
162
|
+
|
|
163
|
+
// If for some reason a config doesn't have a validator/type, skip it
|
|
164
|
+
if (!type) continue;
|
|
165
|
+
|
|
166
|
+
switch (type) {
|
|
167
|
+
case 'uint8':
|
|
168
|
+
response[key] = rep_buffer[idx];
|
|
169
|
+
break;
|
|
170
|
+
case 'uint16be':
|
|
171
|
+
response[key] = rep_buffer.readUInt16BE(idx);
|
|
172
|
+
break;
|
|
173
|
+
case 'uint32be':
|
|
174
|
+
response[key] = rep_buffer.readUInt32BE(idx);
|
|
175
|
+
break;
|
|
176
|
+
case 'buffer':
|
|
177
|
+
response[key] = rep_buffer.subarray(idx, idx + length);
|
|
178
|
+
break;
|
|
179
|
+
case 'hex':
|
|
180
|
+
response[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
|
|
181
|
+
break;
|
|
182
|
+
case 'mac':
|
|
183
|
+
response[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if(Object.hasOwn(response, 'destination_address') && response.destination_address.toLowerCase() === '00000000') {
|
|
188
|
+
console.log('##############################');
|
|
189
|
+
console.log('#########Dest Override########');
|
|
190
|
+
console.log('##############################');
|
|
191
|
+
response.destination_address = "0000ffff";
|
|
192
|
+
response.auto_raw_destination_address = "0000ffff";
|
|
193
|
+
};
|
|
194
|
+
return response;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const parse = (d) => {
|
|
198
|
+
return {
|
|
199
|
+
humidity: msbLsb(d[0], d[1])/100,
|
|
200
|
+
temperature: signInt((msbLsb(d[2], d[3])), 16)/100
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// --- 2. EXPORT THE MODULE ---
|
|
205
|
+
// Export the module with all the necessary functions and properties
|
|
206
|
+
// that need to be called from outside the scrip
|
|
207
|
+
return {
|
|
208
|
+
type: 1,
|
|
209
|
+
name: 'Temperature/Humidity',
|
|
210
|
+
parse,
|
|
211
|
+
get_write_buffer_size,
|
|
212
|
+
get_config_map,
|
|
213
|
+
sync_parse
|
|
214
|
+
};
|
|
215
|
+
};
|