@ncd-io/node-red-enterprise-sensors 1.1.5 → 1.2.1
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 +623 -226
- package/package.json +1 -1
- package/wireless.html +179 -37
- package/wireless.js +149 -17
package/wireless.js
CHANGED
|
@@ -355,13 +355,21 @@ module.exports = function(RED) {
|
|
|
355
355
|
node.status(statuses[node._gateway_node.is_config]);
|
|
356
356
|
};
|
|
357
357
|
node.temp_send_1024 = function(frame){
|
|
358
|
-
console.log('TODO - Move to Emitter');
|
|
358
|
+
console.log('node.temp_send_1024 TODO - Move to Emitter');
|
|
359
359
|
node.send({
|
|
360
360
|
topic: "remote_at_response",
|
|
361
361
|
payload: frame,
|
|
362
362
|
time: Date.now()
|
|
363
363
|
});
|
|
364
364
|
}
|
|
365
|
+
node.temp_send_local = function(frame){
|
|
366
|
+
console.log('node.temp_send_local TODO - Move to Emitter');
|
|
367
|
+
node.send({
|
|
368
|
+
topic: "local_at_response",
|
|
369
|
+
payload: frame,
|
|
370
|
+
time: Date.now()
|
|
371
|
+
});
|
|
372
|
+
}
|
|
365
373
|
|
|
366
374
|
node._gateway_node.on('send_manifest', (manifest_data) => {
|
|
367
375
|
node.send({
|
|
@@ -428,6 +436,46 @@ module.exports = function(RED) {
|
|
|
428
436
|
break;
|
|
429
437
|
case "fidelity_test":
|
|
430
438
|
break;
|
|
439
|
+
case "converter_send_single":
|
|
440
|
+
// Example message:
|
|
441
|
+
// msg.topic = 'rs485_single';
|
|
442
|
+
// msg.payload.address = "00:13:a2:00:42:37:3e:e2";
|
|
443
|
+
// msg.payload.data = [0x01, 0x03, 0x00, 0x15, 0x00, 0x01, 0x95, 0xCE];
|
|
444
|
+
// msg.payload.meta = {
|
|
445
|
+
// 'command_id': 'query_water_levels',
|
|
446
|
+
// 'description': 'Query water levels in mm/cm',
|
|
447
|
+
// 'target_parser': 'parse_water_levels'
|
|
448
|
+
// }
|
|
449
|
+
if(msg.payload.hasOwnProperty('meta')){
|
|
450
|
+
node.gateway.queue_bridge_query(msg.payload.address, msg.payload.command, msg.payload.meta);
|
|
451
|
+
}else{
|
|
452
|
+
node.gateway.queue_bridge_query(msg.payload.address, msg.payload.command);
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
case "converter_send_multiple":
|
|
456
|
+
// Example message:
|
|
457
|
+
// msg.topic = 'converter_send_multiple';
|
|
458
|
+
// msg.payload.address = "00:13:a2:00:42:37:3e:e2";
|
|
459
|
+
// msg.payload.commands = [
|
|
460
|
+
// {
|
|
461
|
+
// 'command': [0x01, 0x03, 0x00, 0x15, 0x00, 0x01, 0x95, 0xCE],
|
|
462
|
+
// 'meta': {
|
|
463
|
+
// 'command_id': 'command_1',
|
|
464
|
+
// 'description': 'Example Command 1',
|
|
465
|
+
// 'target_parser': 'parse_water_levels'
|
|
466
|
+
// }
|
|
467
|
+
// },
|
|
468
|
+
// {
|
|
469
|
+
// 'command': [0x01, 0x03, 0x00, 0x15, 0x00, 0x01, 0x95, 0xCE],
|
|
470
|
+
// 'meta': {
|
|
471
|
+
// 'command_id': 'command_2',
|
|
472
|
+
// 'description': 'Example Command 2',
|
|
473
|
+
// 'target_parser': 'parse_temperature'
|
|
474
|
+
// }
|
|
475
|
+
// }
|
|
476
|
+
// ];
|
|
477
|
+
node.gateway.prepare_bridge_query(msg.payload.address, msg.payload.commands);
|
|
478
|
+
break;
|
|
431
479
|
case "start_luber":
|
|
432
480
|
// msg = {
|
|
433
481
|
// 'topic': start_luber,
|
|
@@ -579,8 +627,26 @@ module.exports = function(RED) {
|
|
|
579
627
|
// }
|
|
580
628
|
break;
|
|
581
629
|
case "remote_at_send":
|
|
630
|
+
if(!Object.hasOwn(msg.payload, 'value')){
|
|
631
|
+
msg.payload.value = undefined;
|
|
632
|
+
}else if(typeof msg.payload.value === 'string' ){
|
|
633
|
+
msg.payload.value = Array.from(string2HexArray(msg.payload.value));
|
|
634
|
+
}
|
|
582
635
|
node.gateway.remote_at_send(msg.payload.address, msg.payload.parameter, msg.payload.value, msg.payload.options).then(node.temp_send_1024, console.log).catch(console.log);
|
|
583
636
|
break;
|
|
637
|
+
case "local_at_send":
|
|
638
|
+
// If there is no value then its a read command and the DigiParser is expecting an undefined
|
|
639
|
+
if(!Object.hasOwn(msg.payload, 'value')){
|
|
640
|
+
msg.payload.value = undefined;
|
|
641
|
+
}else if(typeof msg.payload.value === 'string' ){
|
|
642
|
+
// break into byte array. Primarily used for NID and Encryption
|
|
643
|
+
msg.payload.value = Array.from(string2HexArray(msg.payload.value));
|
|
644
|
+
}else if(msg.payload.value !== undefined){
|
|
645
|
+
// The DigiParser checks the constructor and not all Arrays are the same
|
|
646
|
+
msg.payload.value = Array.from(msg.payload.value);
|
|
647
|
+
}
|
|
648
|
+
node.gateway.local_at_send(msg.payload.parameter, msg.payload.value).then(node.temp_send_local, console.log).catch(console.log);
|
|
649
|
+
break;
|
|
584
650
|
default:
|
|
585
651
|
const byteArrayToHexString = byteArray => Array.from(msg.payload.address, byte => ('0' + (byte & 0xFF).toString(16)).slice(-2)).join('');
|
|
586
652
|
node.gateway.control_send(msg.payload.address, msg.payload.data, msg.payload.options).then().catch(console.log);
|
|
@@ -634,6 +700,12 @@ module.exports = function(RED) {
|
|
|
634
700
|
msg1 = {topic:"link_info",payload:d};
|
|
635
701
|
node.send(msg1);
|
|
636
702
|
});
|
|
703
|
+
node.gateway.on('converter_response', (d) => {
|
|
704
|
+
node.set_status();
|
|
705
|
+
d.topic = 'converter_response';
|
|
706
|
+
d.time = Date.now();
|
|
707
|
+
node.send(d);
|
|
708
|
+
});
|
|
637
709
|
|
|
638
710
|
node.set_status();
|
|
639
711
|
node._gateway_node.on('mode_change', (mode) => {
|
|
@@ -702,7 +774,7 @@ module.exports = function(RED) {
|
|
|
702
774
|
|
|
703
775
|
var promises = {};
|
|
704
776
|
// This command is used for OTF on types 53, 80,81,82,83,84, 101, 102, 110, 111, 518, 519
|
|
705
|
-
let original_otf_devices = [53, 80, 81, 82, 83, 84,
|
|
777
|
+
let original_otf_devices = [53, 80, 81, 82, 83, 84, 101, 102, 110, 111, 112, 114, 180, 181, 518, 519, 520, 538];
|
|
706
778
|
if(original_otf_devices.includes(sensor.type)){
|
|
707
779
|
// This command is used for OTF on types 53, 80, 81, 82, 83, 84, 101, 102, 110, 111, 518, 519
|
|
708
780
|
promises.config_enter_otn_mode = node.config_gateway.config_enter_otn_mode(sensor.mac);
|
|
@@ -1869,8 +1941,8 @@ module.exports = function(RED) {
|
|
|
1869
1941
|
if(config.rtc_108){
|
|
1870
1942
|
promises.rtc_108 = node.config_gateway.config_set_rtc_108(mac);
|
|
1871
1943
|
}
|
|
1872
|
-
if(config.
|
|
1873
|
-
promises.
|
|
1944
|
+
if(config.transmission_interval_108_active){
|
|
1945
|
+
promises.transmission_interval_108 = node.config_gateway.config_set_transmission_interval_108(mac, parseInt(config.transmission_interval_108));
|
|
1874
1946
|
}
|
|
1875
1947
|
if(config.shift_one_108_active){
|
|
1876
1948
|
promises.shift_time1 = node.config_gateway.config_set_shift_one_108(mac, parseInt(config.shift_one_hours_108), parseInt(config.shift_one_minutes_108));
|
|
@@ -1884,6 +1956,9 @@ module.exports = function(RED) {
|
|
|
1884
1956
|
if(config.shift_four_108_active){
|
|
1885
1957
|
promises.shift_time4 = node.config_gateway.config_set_shift_four_108(mac, parseInt(config.shift_four_hours_108), parseInt(config.shift_four_minutes_108));
|
|
1886
1958
|
}
|
|
1959
|
+
if(config.quality_of_service_108_active){
|
|
1960
|
+
promises.quality_of_service_108 = node.config_gateway.config_set_quality_of_service_108(mac, parseInt(config.quality_of_service_108));
|
|
1961
|
+
}
|
|
1887
1962
|
break;
|
|
1888
1963
|
case 110:
|
|
1889
1964
|
if(config.odr_p1_110_active){
|
|
@@ -1892,9 +1967,6 @@ module.exports = function(RED) {
|
|
|
1892
1967
|
if(config.sampling_duration_p1_110_active){
|
|
1893
1968
|
promises.sampling_duration_p1_110 = node.config_gateway.config_set_sampling_duration_p1_110(mac, parseInt(config.sampling_duration_p1_110));
|
|
1894
1969
|
}
|
|
1895
|
-
if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
|
|
1896
|
-
promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
|
|
1897
|
-
}
|
|
1898
1970
|
if(config.sampling_interval_110_active){
|
|
1899
1971
|
promises.sampling_interval_110 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_110));
|
|
1900
1972
|
}
|
|
@@ -1952,6 +2024,9 @@ module.exports = function(RED) {
|
|
|
1952
2024
|
if(config.enable_rpm_calculate_status_110_active){
|
|
1953
2025
|
promises.enable_rpm_calculate_status_110 = node.config_gateway.config_set_enable_rpm_calculate_status_110(mac, parseInt(config.enable_rpm_calculate_status_110));
|
|
1954
2026
|
}
|
|
2027
|
+
if(config.max_raw_sample_110_active){
|
|
2028
|
+
promises.max_raw_sample_110 = node.config_gateway.config_set_max_raw_sample_110(mac, parseInt(config.max_raw_sample_110));
|
|
2029
|
+
}
|
|
1955
2030
|
break;
|
|
1956
2031
|
case 111:
|
|
1957
2032
|
if(config.odr_p1_110_active){
|
|
@@ -1966,9 +2041,6 @@ module.exports = function(RED) {
|
|
|
1966
2041
|
if(config.sampling_duration_p2_110_active){
|
|
1967
2042
|
promises.sampling_duration_p2_111 = node.config_gateway.config_set_sampling_duration_p2_110(mac, parseInt(config.sampling_duration_p2_110));
|
|
1968
2043
|
}
|
|
1969
|
-
if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
|
|
1970
|
-
promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
|
|
1971
|
-
}
|
|
1972
2044
|
if(config.sampling_interval_110_active){
|
|
1973
2045
|
promises.sampling_interval_110 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_110));
|
|
1974
2046
|
}
|
|
@@ -2038,6 +2110,9 @@ module.exports = function(RED) {
|
|
|
2038
2110
|
if(config.enable_rpm_calculate_status_110_active){
|
|
2039
2111
|
promises.enable_rpm_calculate_status_111 = node.config_gateway.config_set_enable_rpm_calculate_status_110(mac, parseInt(config.enable_rpm_calculate_status_110));
|
|
2040
2112
|
}
|
|
2113
|
+
if(config.max_raw_sample_110_active){
|
|
2114
|
+
promises.max_raw_sample_110 = node.config_gateway.config_set_max_raw_sample_110(mac, parseInt(config.max_raw_sample_110));
|
|
2115
|
+
}
|
|
2041
2116
|
break;
|
|
2042
2117
|
case 112:
|
|
2043
2118
|
if(config.current_calibration_82_active){
|
|
@@ -2049,9 +2124,6 @@ module.exports = function(RED) {
|
|
|
2049
2124
|
if(config.sampling_duration_p1_110_active){
|
|
2050
2125
|
promises.sampling_duration_p1_112 = node.config_gateway.config_set_sampling_duration_p1_110(mac, parseInt(config.sampling_duration_p1_110));
|
|
2051
2126
|
}
|
|
2052
|
-
if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
|
|
2053
|
-
promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
|
|
2054
|
-
}
|
|
2055
2127
|
if(config.sampling_interval_110_active){
|
|
2056
2128
|
promises.sampling_interval_110 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_110));
|
|
2057
2129
|
}
|
|
@@ -2130,6 +2202,9 @@ module.exports = function(RED) {
|
|
|
2130
2202
|
if(config.enable_rpm_calculate_status_110_active){
|
|
2131
2203
|
promises.enable_rpm_calculate_status_112 = node.config_gateway.config_set_enable_rpm_calculate_status_110(mac, parseInt(config.enable_rpm_calculate_status_110));
|
|
2132
2204
|
}
|
|
2205
|
+
if(config.max_raw_sample_110_active){
|
|
2206
|
+
promises.max_raw_sample_110 = node.config_gateway.config_set_max_raw_sample_110(mac, parseInt(config.max_raw_sample_110));
|
|
2207
|
+
}
|
|
2133
2208
|
break;
|
|
2134
2209
|
case 114:
|
|
2135
2210
|
if(config.odr_p1_110_active){
|
|
@@ -2138,9 +2213,6 @@ module.exports = function(RED) {
|
|
|
2138
2213
|
if(config.sampling_duration_p1_110_active){
|
|
2139
2214
|
promises.sampling_duration_p1_114 = node.config_gateway.config_set_sampling_duration_p1_110(mac, parseInt(config.sampling_duration_p1_110));
|
|
2140
2215
|
}
|
|
2141
|
-
if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
|
|
2142
|
-
promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
|
|
2143
|
-
}
|
|
2144
2216
|
if(config.sampling_interval_110_active){
|
|
2145
2217
|
promises.sampling_interval_110 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_110));
|
|
2146
2218
|
}
|
|
@@ -2207,6 +2279,9 @@ module.exports = function(RED) {
|
|
|
2207
2279
|
if(config.enable_rpm_calculate_status_110_active){
|
|
2208
2280
|
promises.enable_rpm_calculate_status_110 = node.config_gateway.config_set_enable_rpm_calculate_status_110(mac, parseInt(config.enable_rpm_calculate_status_110));
|
|
2209
2281
|
}
|
|
2282
|
+
if(config.max_raw_sample_110_active){
|
|
2283
|
+
promises.max_raw_sample_110 = node.config_gateway.config_set_max_raw_sample_110(mac, parseInt(config.max_raw_sample_110));
|
|
2284
|
+
}
|
|
2210
2285
|
break;
|
|
2211
2286
|
case 118:
|
|
2212
2287
|
if(config.pressure_sensor_fs_ch1_118_active){
|
|
@@ -2225,6 +2300,23 @@ module.exports = function(RED) {
|
|
|
2225
2300
|
promises.temp_auto_check_percent_118 = node.config_gateway.config_set_temp_auto_check_percent_118(mac, parseInt(config.temp_auto_check_percent_118));
|
|
2226
2301
|
}
|
|
2227
2302
|
break;
|
|
2303
|
+
case 120:
|
|
2304
|
+
if(config.stay_on_mode_539_active){
|
|
2305
|
+
promises.stay_on_mode_120 = node.config_gateway.config_set_stay_on_mode_539(mac, parseInt(config.stay_on_mode_539));
|
|
2306
|
+
}
|
|
2307
|
+
if(config.always_on_120){
|
|
2308
|
+
promises.always_on_120 = node.config_gateway.config_set_to_always_on_120(mac);
|
|
2309
|
+
}
|
|
2310
|
+
if(config.sensor_reset_120){
|
|
2311
|
+
promises.sensor_reset_120 = node.config_gateway.config_set_sensor_reset_120(mac);
|
|
2312
|
+
}
|
|
2313
|
+
if(config.sensor_calib_120){
|
|
2314
|
+
promises.sensor_calib_120 = node.config_gateway.config_set_sensor_calib_120(mac);
|
|
2315
|
+
}
|
|
2316
|
+
if(config.alert_threshold_120_active){
|
|
2317
|
+
promises.alert_threshold_120 = node.config_gateway.config_set_alert_threshold_120(mac, parseInt(config.alert_threshold_120));
|
|
2318
|
+
}
|
|
2319
|
+
break;
|
|
2228
2320
|
case 180:
|
|
2229
2321
|
if(config.output_data_rate_101_active){
|
|
2230
2322
|
promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
|
|
@@ -2347,6 +2439,14 @@ module.exports = function(RED) {
|
|
|
2347
2439
|
promises.probe_boot_time_202 = node.config_gateway.config_set_probe_boot_time_202(mac, parseInt(config.probe_boot_time_202));
|
|
2348
2440
|
}
|
|
2349
2441
|
break;
|
|
2442
|
+
case 217:
|
|
2443
|
+
if(config.tare_the_scale_217){
|
|
2444
|
+
promises.tare_the_scale_217 = node.config_gateway.config_set_tare_the_scale_217(mac);
|
|
2445
|
+
}
|
|
2446
|
+
if(config.weight_calib_217_active){
|
|
2447
|
+
promises.weight_calib_217 = node.config_gateway.config_set_weight_calib_217(mac, parseInt(config.weight_calib_217));
|
|
2448
|
+
}
|
|
2449
|
+
break;
|
|
2350
2450
|
case 505:
|
|
2351
2451
|
if(config.current_calibration_c1_80_active){
|
|
2352
2452
|
promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
|
|
@@ -2640,7 +2740,7 @@ module.exports = function(RED) {
|
|
|
2640
2740
|
}
|
|
2641
2741
|
}
|
|
2642
2742
|
// These sensors listed in original_otf_devices use a different OTF code.
|
|
2643
|
-
let original_otf_devices = [53, 80, 81, 82, 83, 84,
|
|
2743
|
+
let original_otf_devices = [53, 80, 81, 82, 83, 84, 101, 102, 110, 111, 112, 114, 180, 181, 518, 519, 520, 538];
|
|
2644
2744
|
// If we changed the network ID reboot the sensor to take effect.
|
|
2645
2745
|
// TODO if we add the encryption key command to node-red we need to reboot for it as well.
|
|
2646
2746
|
if(reboot){
|
|
@@ -2717,6 +2817,13 @@ module.exports = function(RED) {
|
|
|
2717
2817
|
time: Date.now()
|
|
2718
2818
|
});
|
|
2719
2819
|
});
|
|
2820
|
+
this.gtw_on('converter_response-'+config.addr, (data) => {
|
|
2821
|
+
node.status(modes.RUN);
|
|
2822
|
+
data.modem_mac = this.gateway.modem_mac;
|
|
2823
|
+
data.topic = 'converter_response';
|
|
2824
|
+
data.time = Date.now();
|
|
2825
|
+
node.send(data);
|
|
2826
|
+
});
|
|
2720
2827
|
this.gtw_on('set_destination_address'+config.addr, (d) => {
|
|
2721
2828
|
if(config.auto_config){
|
|
2722
2829
|
node.warn('Setting destination address');
|
|
@@ -3080,6 +3187,31 @@ function int2Bytes(i, l){
|
|
|
3080
3187
|
}
|
|
3081
3188
|
return bytes;
|
|
3082
3189
|
}
|
|
3190
|
+
function string2HexArray(hexString) {
|
|
3191
|
+
if (typeof hexString !== 'string') {
|
|
3192
|
+
console.error('Input must be a string.');
|
|
3193
|
+
return undefined;
|
|
3194
|
+
}
|
|
3195
|
+
|
|
3196
|
+
const cleanedHexString = hexString.replace(/:/g, ''); //Remove colons.
|
|
3197
|
+
|
|
3198
|
+
if (cleanedHexString.length % 2 !== 0) {
|
|
3199
|
+
console.error('Hex string length must be divisible by two.');
|
|
3200
|
+
return undefined;
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
let byteArray = [];
|
|
3204
|
+
for (let i = 0; i < cleanedHexString.length; i += 2) {
|
|
3205
|
+
const byte = cleanedHexString.substring(i, i + 2);
|
|
3206
|
+
const byteValue = parseInt(byte, 16);
|
|
3207
|
+
if (isNaN(byteValue)) {
|
|
3208
|
+
console.error("Invalid hex character in string");
|
|
3209
|
+
return undefined;
|
|
3210
|
+
}
|
|
3211
|
+
byteArray.push(byteValue);
|
|
3212
|
+
}
|
|
3213
|
+
return byteArray;
|
|
3214
|
+
}
|
|
3083
3215
|
function toHex(n){return ('00' + n.toString(16)).substr(-2);}
|
|
3084
3216
|
function toMac(arr){
|
|
3085
3217
|
return arr.reduce((h,c,i) => {return ((i==1?toHex(h):h)+':'+toHex(c)).toUpperCase();});
|