@ncd-io/node-red-enterprise-sensors 1.4.0 → 1.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ncd-io/node-red-enterprise-sensors",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wireless.html CHANGED
@@ -714,7 +714,12 @@
714
714
  fsr_420ma_active: {value: ""},
715
715
  fsr_420ma: {value: 0},
716
716
  always_on_420ma_active: {value: ""},
717
- always_on_420ma: {value: 0}
717
+ always_on_420ma: {value: 0},
718
+
719
+ pressure_sensor_range_AMS5812_21_active: {value: ""},
720
+ pressure_sensor_range_AMS5812_21: {value: 0},
721
+ pressure_sensor_range_AMS5915_21_active: {value: ""},
722
+ pressure_sensor_range_AMS5915_21: {value: 0}
718
723
  },
719
724
  inputs: 0,
720
725
  outputs: 1,
@@ -3262,9 +3267,6 @@
3262
3267
  <label for="node-input-motion_detect_threshold_p1_110"><i class="icon-tag"></i> Value</label>
3263
3268
  <input type="text" id="node-input-motion_detect_threshold_p1_110" placeholder="10" value="10">
3264
3269
  </div>
3265
- <p class="caption">
3266
- <i>Note: Only applies to sensor with firmware version 24 and above.</i>
3267
- </p>
3268
3270
  </div>
3269
3271
  </div>
3270
3272
  <div class="ncd-dependent" data-sensor-111>
@@ -3285,9 +3287,6 @@
3285
3287
  <label for="node-input-motion_detect_threshold_p2_110"><i class="icon-tag"></i> Value</label>
3286
3288
  <input type="text" id="node-input-motion_detect_threshold_p2_110" placeholder="10" value="10">
3287
3289
  </div>
3288
- <p class="caption">
3289
- <i>Note: Only applies to sensor with firmware version 24 and above.</i>
3290
- </p>
3291
3290
  </div>
3292
3291
  </div>
3293
3292
  <div class="ncd-dependent" data-sensor-80 data-sensor-81 data-sensor-82 data-sensor-84 data-sensor-110 data-sensor-111 data-sensor-112 data-sensor-114 data-sensor-180 data-sensor-181 data-sensor-519 data-sensor-537 data-sensor-538>
@@ -4488,7 +4487,21 @@
4488
4487
  </div>
4489
4488
  <div class="ncd-dependent" data-sensor-21>
4490
4489
  <div class="form-row ncd-active-check">
4491
- <strong>Set Pressure Sensor Type (code)</strong>
4490
+ <strong>Set Pressure Sensor Type</strong>
4491
+ <div>
4492
+ <label for="node-input-pressure_sensor_type_21_active">Active:</label>
4493
+ <input type="checkbox" id="node-input-pressure_sensor_type_21_active" class="ncd-config-toggle" data-target-id="node-input-pressure_sensor_type_21" value="1">
4494
+ </div>
4495
+ <div>
4496
+ <label for="node-input-pressure_sensor_type_21"><i class="icon-tag"></i>Value:</label>
4497
+ <select id="node-input-pressure_sensor_type_21">
4498
+ <option value="0">AMS5812</option>
4499
+ <option value="1">AMS5915</option>
4500
+ </select>
4501
+ </div>
4502
+ </div>
4503
+ <div class="form-row ncd-active-check">
4504
+ <strong>Set Pressure Sensor Range (for AMS5812)</strong>
4492
4505
  <p>
4493
4506
  D: Differential/relative.<br>
4494
4507
  D-B: Bidirectional Differential.<br>
@@ -4496,12 +4509,12 @@
4496
4509
  B: Absolute (barometric).<br>
4497
4510
  </p>
4498
4511
  <div>
4499
- <label for="node-input-pressure_sensor_type_21_active">Active:</label>
4500
- <input type="checkbox" id="node-input-pressure_sensor_type_21_active" class="ncd-config-toggle" data-target-id="node-input-pressure_sensor_type_21" value="1">
4512
+ <label for="node-input-pressure_sensor_range_AMS5812_21_active">Active:</label>
4513
+ <input type="checkbox" id="node-input-pressure_sensor_range_AMS5812_21_active" class="ncd-config-toggle" data-target-id="node-input-pressure_sensor_range_AMS5812_21" value="1">
4501
4514
  </div>
4502
4515
  <div>
4503
- <label for="node-input-pressure_sensor_type_21"><i class="icon-tag"></i>Value:</label>
4504
- <select id="node-input-pressure_sensor_type_21">
4516
+ <label for="node-input-pressure_sensor_range_AMS5812_21"><i class="icon-tag"></i>Value:</label>
4517
+ <select id="node-input-pressure_sensor_range_AMS5812_21">
4505
4518
  <option value="0">Type 0000-D</option>
4506
4519
  <option value="1">Type 0001-D</option>
4507
4520
  <option value="2">Type 0000-D-B</option>
@@ -4527,6 +4540,49 @@
4527
4540
  </select>
4528
4541
  </div>
4529
4542
  </div>
4543
+ <div class="form-row ncd-active-check">
4544
+ <strong>Set Pressure Sensor Range (for AMS5915)</strong>
4545
+ <p>
4546
+ D: Differential/relative.<br>
4547
+ D-B: Bidirectional Differential.<br>
4548
+ A: Absolute.<br>
4549
+ B: Absolute (barometric).<br>
4550
+ </p>
4551
+ <div>
4552
+ <label for="node-input-pressure_sensor_range_AMS5915_21_active">Active:</label>
4553
+ <input type="checkbox" id="node-input-pressure_sensor_range_AMS5915_21_active" class="ncd-config-toggle" data-target-id="node-input-pressure_sensor_range_AMS5915_21" value="1">
4554
+ </div>
4555
+ <div>
4556
+ <label for="node-input-pressure_sensor_range_AMS5915_21"><i class="icon-tag"></i>Value:</label>
4557
+ <select id="node-input-pressure_sensor_range_AMS5915_21">
4558
+ <option value="0">Type 0005-D</option>
4559
+ <option value="1">Type 0010_D</option>
4560
+ <option value="2">Type 0002_D_B</option>
4561
+ <option value="3">Type 0005_D_B</option>
4562
+ <option value="4">Type 0010_D_B</option>
4563
+ <option value="5">Type 0020_D</option>
4564
+ <option value="6">Type 0035_D</option>
4565
+ <option value="7">Type 0050_D</option>
4566
+ <option value="8">Type 0100_D</option>
4567
+ <option value="9">Type 0020_D_B</option>
4568
+ <option value="10">Type 0035_D_B</option>
4569
+ <option value="11">Type 0050_D_B</option>
4570
+ <option value="12">Type 0100_D_B</option>
4571
+ <option value="13">Type 0200_D</option>
4572
+ <option value="14">Type 0350_D</option>
4573
+ <option value="15">Type 0500_D</option>
4574
+ <option value="16">Type 1000_D</option>
4575
+ <option value="17">Type 2000_D</option>
4576
+ <option value="18">Type 4000_D</option>
4577
+ <option value="19">Type 7000_D</option>
4578
+ <option value="20">Type 10000_D</option>
4579
+ <option value="21">Type 0200_D_B</option>
4580
+ <option value="22">Type 0350_D_B</option>
4581
+ <option value="23">Type 0500_D_B</option>
4582
+ <option value="24">Type 1000_D_B</option>
4583
+ </select>
4584
+ </div>
4585
+ </div>
4530
4586
  </div>
4531
4587
  <div class="ncd-dependent" data-sensor-120>
4532
4588
  <div class="form-row ncd-active-check">
package/wireless.js CHANGED
@@ -150,15 +150,18 @@ module.exports = function(RED) {
150
150
  // enter ota mode
151
151
  node.gateway.digi.send.at_command("ID", [0x7a, 0xaa]).then().catch().then(() => {
152
152
  console.log(manifest_data);
153
- if(manifest_data.enter_ota_fota_version <13){
154
- console.log('OLD PROCESSS');
153
+ if(manifest_data.enter_ota_fota_version > 16){
154
+ console.log('V17 PROCESS');
155
155
  console.log(manifest_data);
156
- // console.log(firmware_data);
157
- node.start_firmware_update(manifest_data, firmware_data);
158
- }else{
159
- console.log('NEW PROCESS');
156
+ node.start_firmware_update_v17(manifest_data, firmware_data);
157
+ }else if(manifest_data.enter_ota_fota_version > 12){
158
+ console.log('V13 PROCESS');
160
159
  console.log(manifest_data);
161
160
  node.start_firmware_update_v13(manifest_data, firmware_data);
161
+ }else{
162
+ console.log('OLD PROCESSS');
163
+ console.log(manifest_data);
164
+ node.start_firmware_update(manifest_data, firmware_data);
162
165
  }
163
166
  });
164
167
  }
@@ -352,6 +355,119 @@ module.exports = function(RED) {
352
355
  }
353
356
  });
354
357
  };
358
+ node.start_firmware_update_v17 = function(manifest_data, firmware_data){
359
+ console.log('V17 Update Start');
360
+ var start_offset = 0;
361
+ setTimeout(() => {
362
+ if(Object.hasOwn(node.sensor_list[manifest_data.addr], 'last_chunk_success')){
363
+ node.gateway.firmware_read_last_chunk_segment(manifest_data.addr).then((status_frame) => {
364
+ console.log('Last Chunk Segment Read');
365
+ console.log(status_frame);
366
+ start_offset = status_frame.data.slice(4,8).reduce(msbLsb);
367
+ node.queue_firmware_update_v17(manifest_data, firmware_data, start_offset);
368
+ }).catch((err) => {
369
+ // TODO FOTA EMIT ERROR FOTA
370
+ console.log('Error reading last chunk segment');
371
+ node.resume_normal_operation();
372
+ });
373
+ }else{
374
+ node.queue_firmware_update_v17(manifest_data, firmware_data, start_offset);
375
+ };
376
+ }, 1000);
377
+ };
378
+ node.queue_firmware_update_v17 = function(manifest_data, firmware_data, start_offset){
379
+ console.log('V17 Queue Update Start');
380
+ console.log('Start Offset: '+start_offset);
381
+ return new Promise((top_fulfill, top_reject) => {
382
+ var success = {successes:{}, failures:{}};
383
+
384
+ let chunk_size = 128;
385
+ let image_start = firmware_data.firmware.slice(1, 5).reduce(msbLsb)+6;
386
+ var promises = {};
387
+ if(start_offset == 0){
388
+ promises.manifest = node.gateway.firmware_send_manifest(manifest_data.addr, firmware_data.firmware.slice(5, image_start-1));
389
+ };
390
+ // promises.manifest = node.gateway.firmware_send_manifest(manifest_data.addr, firmware_data.firmware.slice(5, image_start-1));
391
+ firmware_data.firmware = firmware_data.firmware.slice(image_start+4);
392
+
393
+ // if(Object.hasOwn(node.sensor_list[manifest_data.addr], 'last_chunk_success')){
394
+ // index = node.sensor_list[manifest_data.addr].last_chunk_success;
395
+ // }
396
+
397
+ // reverse calculate index based on start_offset.
398
+ var index = parseInt(start_offset / chunk_size);
399
+ console.log('Index: '+index);
400
+ while(index*chunk_size < firmware_data.manifest.image_size){
401
+ let offset = index*chunk_size;
402
+ let offset_bytes = int2Bytes(offset, 4);
403
+ let firmware_chunk = firmware_data.firmware.slice(index*chunk_size, index*chunk_size+chunk_size);
404
+ promises[index] = node.gateway.firmware_send_chunk_v13(manifest_data.addr, offset_bytes, firmware_chunk);
405
+ if(((index + 1) % 50) == 0 || (index+1)*chunk_size >= firmware_data.manifest.image_size){
406
+ promises[index+'_check'] = node.gateway.firmware_read_last_chunk_segment(manifest_data.addr);
407
+ };
408
+ index++;
409
+ }
410
+ console.log('Update Started');
411
+ console.log(Object.keys(promises).length);
412
+ console.log(Date.now());
413
+ promises.reboot = node.gateway.config_reboot_sensor(manifest_data.addr);
414
+ var firmware_continue = true;
415
+ for(var i in promises){
416
+ (function(name){
417
+ let retryCount = 0;
418
+ const maxRetries = 3; // Set the maximum number of retries
419
+
420
+ function attemptPromise() {
421
+ console.log(name);
422
+ promises[name].then((status_frame) => {
423
+ if(name == 'manifest'){
424
+ console.log('MANIFEST SUCCESFULLY SENT');
425
+ node.sensor_list[manifest_data.addr].test_check = {name: true};
426
+ node.sensor_list[manifest_data.addr].update_in_progress = true;
427
+ }
428
+ else if(name.includes('_check')){
429
+ console.log(name);
430
+ console.log(parseInt(name.split('_')[0]) * chunk_size);
431
+ let last_chunk = status_frame.data.slice(0,4).reduce(msbLsb);
432
+ console.log(last_chunk);
433
+ if(last_chunk != (parseInt(name.split('_')[0]) * chunk_size)){
434
+ console.log('ERROR DETECTED IN OTA UPDATE');
435
+ success.failures[name] = {chunk: last_chunk, last_transmit: (parseInt(name.split('_')[0]) * chunk_size), last_report: last_chunk};
436
+ // node.gateway.clear_queue_except_last();
437
+ node.gateway.clear_queue();
438
+ node.resume_normal_operation();
439
+ } else {
440
+ success.successes[name] = {chunk: last_chunk};
441
+ }
442
+ }
443
+ else {
444
+ success[name] = true;
445
+ node.sensor_list[manifest_data.addr].test_check[name] = true;
446
+ node.sensor_list[manifest_data.addr].last_chunk_success = name;
447
+ }
448
+ }).catch((err) => {
449
+ console.log(name);
450
+ console.log(err);
451
+ if(name != 'reboot'){
452
+ node.gateway.clear_queue();
453
+ success[name] = err;
454
+ } else {
455
+ delete node.sensor_list[manifest_data.addr].last_chunk_success;
456
+ delete node.sensor_list[manifest_data.addr].update_request;
457
+ node._emitter.emit('send_firmware_stats', {state: success, addr: manifest_data.addr});
458
+ top_fulfill(success);
459
+ }
460
+ console.log('Update Finished')
461
+ console.log(Date.now());
462
+ node._emitter.emit('send_firmware_stats', {state: success, addr: manifest_data.addr});
463
+ node.resume_normal_operation();
464
+ });
465
+ }
466
+ attemptPromise(); // Start the initial attempt
467
+ })(i);
468
+ }
469
+ });
470
+ }
355
471
  node.resume_normal_operation = function(){
356
472
  let pan_id = parseInt(config.pan_id, 16);
357
473
  node.gateway.digi.send.at_command("ID", [pan_id >> 8, pan_id & 255]).then().catch().then(() => {
@@ -450,6 +566,18 @@ module.exports = function(RED) {
450
566
 
451
567
  node.on('close', function(){
452
568
  this._gateway_node.close_comms();
569
+ this._gateway_node._emitter.removeAllListeners('send_manifest');
570
+ this._gateway_node._emitter.removeAllListeners('send_firmware_stats');
571
+ this._gateway_node._emitter.removeAllListeners('mode_change');
572
+ this.gateway._emitter.removeAllListeners('ncd_error');
573
+ this.gateway._emitter.removeAllListeners('sensor_data');
574
+ this.gateway._emitter.removeAllListeners('sensor_mode');
575
+ this.gateway._emitter.removeAllListeners('receive_packet-unknown_device');
576
+ this.gateway._emitter.removeAllListeners('route_info');
577
+ this.gateway._emitter.removeAllListeners('link_info');
578
+ this.gateway._emitter.removeAllListeners('converter_response');
579
+ this.gateway._emitter.removeAllListeners('manifest_received');
580
+ console.log(this.gateway._emitter.eventNames());
453
581
  });
454
582
 
455
583
  node.is_config = false;
@@ -555,10 +683,13 @@ module.exports = function(RED) {
555
683
  // 'description': 'Query water levels in mm/cm',
556
684
  // 'target_parser': 'parse_water_levels'
557
685
  // }
686
+ if(!Object.hasOwn(msg.payload, 'timeout')){
687
+ msg.payload.timeout = 1500;
688
+ }
558
689
  if(msg.payload.hasOwnProperty('meta')){
559
- node.gateway.queue_bridge_query(msg.payload.address, msg.payload.command, msg.payload.meta);
690
+ node.gateway.queue_bridge_query(msg.payload.address, msg.payload.command, msg.payload.meta, msg.payload.timeout);
560
691
  }else{
561
- node.gateway.queue_bridge_query(msg.payload.address, msg.payload.command);
692
+ node.gateway.queue_bridge_query(msg.payload.address, msg.payload.command, null, msg.payload.timeout);
562
693
  }
563
694
  break;
564
695
  case "converter_send_multiple":
@@ -583,7 +714,10 @@ module.exports = function(RED) {
583
714
  // }
584
715
  // }
585
716
  // ];
586
- node.gateway.prepare_bridge_query(msg.payload.address, msg.payload.commands);
717
+ if(!Object.hasOwn(msg.payload, 'timeout')){
718
+ msg.payload.timeout = 1500;
719
+ }
720
+ node.gateway.prepare_bridge_query(msg.payload.address, msg.payload.commands, msg.payload.timeout);
587
721
  break;
588
722
  case "start_luber":
589
723
  // msg = {
@@ -739,10 +873,10 @@ module.exports = function(RED) {
739
873
  // }
740
874
  // TODO unfinished
741
875
  msg.payload.addresses.forEach((address) => {
742
- if(!Object.hasOwn(node._gateway_node.sensor_list, msg.payload.address)){
876
+ if(!Object.hasOwn(node._gateway_node.sensor_list, address)){
743
877
  node._gateway_node.sensor_list[address] = {};
744
878
  };
745
- if(!Object.hasOwn(node._gateway_node.sensor_list[msg.payload.address], 'update_request')){
879
+ if(!Object.hasOwn(node._gateway_node.sensor_list[address], 'update_request')){
746
880
  node._gateway_node.sensor_list[address].update_request = true;
747
881
  };
748
882
  });
@@ -1251,6 +1385,12 @@ module.exports = function(RED) {
1251
1385
  if(config.pressure_sensor_type_21_active){
1252
1386
  promises.pressure_sensor_type_21 = node.config_gateway.config_set_pressure_sensor_type_21(mac, parseInt(config.pressure_sensor_type_21));
1253
1387
  }
1388
+ if(config.pressure_sensor_range_AMS5812_21_active){
1389
+ promises.pressure_sensor_range_AMS5812_21 = node.config_gateway.config_set_pressure_sensor_range_21(mac, parseInt(config.pressure_sensor_range_AMS5812_21));
1390
+ }
1391
+ if(config.pressure_sensor_range_AMS5915_21_active){
1392
+ promises.pressure_sensor_range_AMS5915_21 = node.config_gateway.config_set_pressure_sensor_range_21(mac, parseInt(config.pressure_sensor_range_AMS5915_21));
1393
+ }
1254
1394
  break;
1255
1395
  case 23:
1256
1396
  if(config.thermocouple_type_23_active){
@@ -3344,9 +3484,10 @@ module.exports = function(RED) {
3344
3484
  for(var p in pgm_events){
3345
3485
  node.config_gateway._emitter.removeAllListeners(p);
3346
3486
  }
3487
+
3347
3488
  node.gateway_node.close_comms();
3348
3489
  if(typeof node.config_gateway_node != 'undefined'){
3349
- node.config_gateway_node.close_comms();
3490
+ console.log(node.config_gateway_node.close_comms());
3350
3491
  }
3351
3492
  });
3352
3493
  }