@ncd-io/node-red-enterprise-sensors 0.1.4 → 0.1.6

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/wireless.js CHANGED
@@ -51,12 +51,17 @@ module.exports = function(RED) {
51
51
  this.gateway.digi.report_rssi = config.rssi;
52
52
 
53
53
  if(config.comm_type == 'serial'){
54
- node.gateway.digi.serial.setupSerial();
54
+ setTimeout(()=>{node.gateway.digi.serial.setupSerial()}, 5000);
55
55
  }else{
56
- node.gateway.digi.serial.setupClient();
56
+ setTimeout(()=>{node.gateway.digi.serial.setupClient()}, 5000);
57
57
  }
58
58
  node.gateway.digi.serial.on('ready', () => {
59
- node.check_mode((mode) => {
59
+ node.gateway.digi.send.at_command('SL').then((res) => {
60
+ node.gateway.modem_mac = '00:13:A2:00:'+toMac(res.data);
61
+ }).catch((err) => {
62
+ console.log(err);
63
+ node.gateway.digi.serial.reconnect();
64
+ }).then(node.check_mode((mode) => {
60
65
  var pan_id = parseInt(config.pan_id, 16);
61
66
  // if(!mode && node.gateway.pan_id != pan_id){
62
67
  if(node.gateway.pan_id != pan_id){
@@ -67,13 +72,7 @@ module.exports = function(RED) {
67
72
  node.gateway.digi.serial.reconnect();
68
73
  });
69
74
  }
70
- });
71
- node.gateway.digi.send.at_command('SL').then((res) => {
72
- node.gateway.modem_mac = '00:13:A2:00:'+toMac(res.data);
73
- }).catch((err) => {
74
- console.log(err);
75
- node.gateway.digi.serial.reconnect();
76
- });
75
+ }));
77
76
  });
78
77
  node.gateway.digi.serial.on('closed_comms', () => {
79
78
  node.is_config = 3;
@@ -183,902 +182,974 @@ module.exports = function(RED) {
183
182
 
184
183
 
185
184
  function NcdWirelessNode(config){
186
- RED.nodes.createNode(this,config);
187
- this.gateway_node = RED.nodes.getNode(config.connection);
188
- this.gateway_node.open_comms();
189
- this.gateway = this.gateway_node.gateway;
190
- var dedicated_config = false;
191
- this.config_gateway = this.gateway;
185
+ RED.nodes.createNode(this,config);
186
+ this.gateway_node = RED.nodes.getNode(config.connection);
187
+ this.gateway_node.open_comms();
188
+ this.gateway = this.gateway_node.gateway;
189
+ var dedicated_config = false;
190
+ this.config_gateway = this.gateway;
192
191
 
193
- if(config.config_comm){
194
- this.config_gateway_node = RED.nodes.getNode(config.config_comm);
195
- this.config_gateway_node.open_comms();
196
- this.config_gateway = this.config_gateway_node.gateway;
197
- dedicated_config = true;
198
- }
199
- this.queue = new Queue(1);
200
- var node = this;
201
- var modes = {
202
- PGM: {fill:"red",shape:"dot",text:"Config Mode"},
203
- PGM_NOW: {fill:"red",shape:"dot",text:"Configuring..."},
204
- READY: {fill: "green", shape: "ring", text:"Config Complete"},
205
- PGM_ERR: {fill:"red", shape:"ring", text:"Config Error"},
206
- RUN: {fill:"green",shape:"dot",text:"Running"},
207
- PUM: {fill:"yellow",shape:"ring",text:"Module was factory reset"},
208
- ACK: {fill:"green",shape:"ring",text:"Configuration Acknowledged"},
209
- // FLY: {fill:"yellow",shape:"ring",text:"FLY notification received"},
210
- // OTN: {fill:"yellow",shape:"ring",text:"OTN Received, OTF Configuration Initiated"},
211
- // OFF: {fill:"green",shape:"dot",text:"OFF Recieved, OTF Configuration Completed"}
212
- FLY: {fill:"yellow",shape:"ring",text:"FLY"},
213
- OTN: {fill:"yellow",shape:"ring",text:"OTN Received, Config Entered"},
214
- OTF: {fill:"green",shape:"dot",text:"OTF Received, Config Complete"}
215
- };
216
- var events = {};
217
- var pgm_events = {};
218
- this.gtw_on = (event, cb) => {
219
- events[event] = cb;
220
- this.gateway.on(event, cb);
221
- };
222
- this.pgm_on = (event, cb) => {
223
- events[event] = cb;
224
- this.config_gateway.on(event, cb);
225
- };
226
- function _send_otn_request(sensor){
227
- return new Promise((top_fulfill, top_reject) => {
228
- var msg = {};
229
- setTimeout(() => {
230
- var tout = setTimeout(() => {
231
- node.status(modes.PGM_ERR);
232
- node.send({topic: 'OTN Request Results', payload: msg, time: Date.now()});
233
- }, 10000);
192
+ if(config.config_comm){
193
+ this.config_gateway_node = RED.nodes.getNode(config.config_comm);
194
+ this.config_gateway_node.open_comms();
195
+ this.config_gateway = this.config_gateway_node.gateway;
196
+ dedicated_config = true;
197
+ }
198
+ this.queue = new Queue(1);
199
+ var node = this;
200
+ var modes = {
201
+ PGM: {fill:"red",shape:"dot",text:"Config Mode"},
202
+ PGM_NOW: {fill:"red",shape:"dot",text:"Configuring..."},
203
+ READY: {fill: "green", shape: "ring", text:"Config Complete"},
204
+ PGM_ERR: {fill:"red", shape:"ring", text:"Config Error"},
205
+ RUN: {fill:"green",shape:"dot",text:"Running"},
206
+ PUM: {fill:"yellow",shape:"ring",text:"Module was factory reset"},
207
+ ACK: {fill:"green",shape:"ring",text:"Configuration Acknowledged"},
208
+ // FLY: {fill:"yellow",shape:"ring",text:"FLY notification received"},
209
+ // OTN: {fill:"yellow",shape:"ring",text:"OTN Received, OTF Configuration Initiated"},
210
+ // OFF: {fill:"green",shape:"dot",text:"OFF Recieved, OTF Configuration Completed"}
211
+ FLY: {fill:"yellow",shape:"ring",text:"FLY"},
212
+ OTN: {fill:"yellow",shape:"ring",text:"OTN Received, Config Entered"},
213
+ OTF: {fill:"green",shape:"dot",text:"OTF Received, Config Complete"}
214
+ };
215
+ var events = {};
216
+ var pgm_events = {};
217
+ this.gtw_on = (event, cb) => {
218
+ events[event] = cb;
219
+ this.gateway.on(event, cb);
220
+ };
221
+ this.pgm_on = (event, cb) => {
222
+ events[event] = cb;
223
+ this.config_gateway.on(event, cb);
224
+ };
225
+ function _send_otn_request(sensor){
226
+ return new Promise((top_fulfill, top_reject) => {
227
+ var msg = {};
228
+ setTimeout(() => {
229
+ var tout = setTimeout(() => {
230
+ node.status(modes.PGM_ERR);
231
+ node.send({topic: 'OTN Request Results', payload: msg, time: Date.now()});
232
+ }, 10000);
234
233
 
235
- var promises = {};
236
- // This command is used for OTF on types 53, 80,81,82,83,84, 101, 102 , 518,519
237
- let original_otf_devices = [53, 80, 81, 82, 83, 84, 101, 102 , 518, 519, 520];
238
- if(original_otf_devices.includes(sensor.type)){
239
- // This command is used for OTF on types 53, 80,81,82,83,84, 101, 102 , 518,519
240
- promises.config_enter_otn_mode = node.config_gateway.config_enter_otn_mode(sensor.mac);
241
- }else{
242
- // This command is used for OTF on types not 53, 80,81,82,83,84, 101, 102 , 518,519
243
- promises.config_enter_otn_mode = node.config_gateway.config_enter_otn_mode_common(sensor.mac);
244
- }
245
- promises.finish = new Promise((fulfill, reject) => {
246
- node.config_gateway.queue.add(() => {
247
- return new Promise((f, r) => {
248
- clearTimeout(tout);
249
- node.status(modes.FLY);
250
- fulfill();
251
- f();
252
- });
253
- });
254
- });
255
- for(var i in promises){
256
- (function(name){
257
- promises[name].then((f) => {
258
- if(name != 'finish') msg[name] = true;
259
- else{
260
- // #OTF
261
- node.send({topic: 'OTN Request Results', payload: msg, time: Date.now()});
262
- top_fulfill(msg);
263
- }
264
- }).catch((err) => {
265
- msg[name] = err;
266
- });
267
- })(i);
268
- }
269
- });
270
- });
271
- };
272
- function _broadcast_rtc(sensor){
273
- return new Promise((top_fulfill, top_reject) => {
274
- var msg = {};
275
- setTimeout(() => {
276
- var tout = setTimeout(() => {
277
- node.status(modes.PGM_ERR);
278
- node.send({topic: 'RTC Broadcast', payload: msg, time: Date.now()});
279
- }, 10000);
234
+ var promises = {};
235
+ // This command is used for OTF on types 53, 80,81,82,83,84, 101, 102 , 518,519
236
+ let original_otf_devices = [53, 80, 81, 82, 83, 84, 101, 102 , 518, 519, 520];
237
+ if(original_otf_devices.includes(sensor.type)){
238
+ // This command is used for OTF on types 53, 80,81,82,83,84, 101, 102 , 518,519
239
+ promises.config_enter_otn_mode = node.config_gateway.config_enter_otn_mode(sensor.mac);
240
+ }else{
241
+ // This command is used for OTF on types not 53, 80,81,82,83,84, 101, 102 , 518,519
242
+ promises.config_enter_otn_mode = node.config_gateway.config_enter_otn_mode_common(sensor.mac);
243
+ }
244
+ promises.finish = new Promise((fulfill, reject) => {
245
+ node.config_gateway.queue.add(() => {
246
+ return new Promise((f, r) => {
247
+ clearTimeout(tout);
248
+ node.status(modes.FLY);
249
+ fulfill();
250
+ f();
251
+ });
252
+ });
253
+ });
254
+ for(var i in promises){
255
+ (function(name){
256
+ promises[name].then((f) => {
257
+ if(name != 'finish') msg[name] = true;
258
+ else{
259
+ // #OTF
260
+ node.send({topic: 'OTN Request Results', payload: msg, time: Date.now()});
261
+ top_fulfill(msg);
262
+ }
263
+ }).catch((err) => {
264
+ msg[name] = err;
265
+ });
266
+ })(i);
267
+ }
268
+ });
269
+ });
270
+ };
271
+ function _broadcast_rtc(sensor){
272
+ return new Promise((top_fulfill, top_reject) => {
273
+ var msg = {};
274
+ setTimeout(() => {
275
+ var tout = setTimeout(() => {
276
+ node.status(modes.PGM_ERR);
277
+ node.send({topic: 'RTC Broadcast', payload: msg, time: Date.now()});
278
+ }, 10000);
280
279
 
281
- var promises = {};
280
+ var promises = {};
282
281
 
283
- promises.broadcast_rtc = node.config_gateway.config_set_rtc_101('00:00:00:00:00:00:FF:FF');
282
+ promises.broadcast_rtc = node.config_gateway.config_set_rtc_101('00:00:00:00:00:00:FF:FF');
284
283
 
285
- promises.finish = new Promise((fulfill, reject) => {
286
- node.config_gateway.queue.add(() => {
287
- return new Promise((f, r) => {
288
- clearTimeout(tout);
289
- node.status(modes.FLY);
290
- fulfill();
291
- f();
292
- });
293
- });
294
- });
295
- for(var i in promises){
296
- (function(name){
297
- promises[name].then((f) => {
298
- if(name != 'finish') msg[name] = true;
299
- else{
300
- // #OTF
301
- this.gateway.fly_101_in_progress = false;
302
- node.send({topic: 'RTC Broadcast', payload: msg, time: Date.now()});
303
- top_fulfill(msg);
304
- }
305
- }).catch((err) => {
306
- msg[name] = err;
307
- });
308
- })(i);
309
- }
310
- });
311
- });
312
- }
313
- function _config(sensor, otf = false){
314
- return new Promise((top_fulfill, top_reject) => {
315
- var success = {};
316
- setTimeout(() => {
317
- var tout = setTimeout(() => {
318
- node.status(modes.PGM_ERR);
319
- node.send({topic: 'Config Results', payload: success, time: Date.now()});
320
- }, 60000);
321
- node.status(modes.PGM_NOW);
322
- if(parseInt(config.sensor_type) >= 10000){
323
- if(sensor) return;
324
- var dest = parseInt(config.destination, 16);
325
- if(dest == 65535){
326
- dest = [0,0,0,0,0,0,255,255];
327
- }else{
328
- dest = [0, 0x13, 0xa2, 0, ...int2Bytes(dest, 4)];
329
- }
330
- var promises = {
331
- destination: node.gateway.config_powered_device(config.addr, 'destination', ...dest),
332
- network_id: node.gateway.config_powered_device(config.addr, 'network_id', ...int2Bytes(parseInt(config.pan_id, 16), 2)),
333
- power: node.gateway.config_powered_device(config.addr, 'power', parseInt(config.power)),
334
- retries: node.gateway.config_powered_device(config.addr, 'retries', parseInt(config.retries)),
335
- node_id: node.gateway.config_powered_device(config.addr, 'node_id', parseInt(config.node_id)),
336
- delay: node.gateway.config_powered_device(config.addr, 'delay', ...int2Bytes(parseInt(config.delay), 2))
337
- };
338
- }else{
339
- var mac = sensor.mac;
340
- var promises = {};
341
- var reboot = false;
342
- if(config.form_network){
343
- promises.establish_config_network_1 = node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF');
344
- promises.establish_config_network_2 = node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF');
345
- promises.establish_config_network_3 = node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF');
346
- }
347
- if(config.destination_active){
348
- promises.destination = node.config_gateway.config_set_destination(mac, parseInt(config.destination, 16));
349
- }
350
- if(config.pan_id_active){
351
- reboot = true;
352
- promises.network_id = node.config_gateway.config_set_pan_id(mac, parseInt(config.pan_id, 16));
353
- }
354
- // var promises = {
355
- // // NOTE: establish_config_network_x commands added to force XBee network to form before sending commands.
356
- // establish_config_network_1: node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF'),
357
- // establish_config_network_2: node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF'),
358
- // establish_config_network_3: node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF'),
359
- //
360
- // destination: node.config_gateway.config_set_destination(mac, parseInt(config.destination, 16)),
361
- // network_id: node.config_gateway.config_set_pan_id(mac, parseInt(config.pan_id, 16))
362
- // };
363
- if(config.node_id_delay_active){
364
- promises.id_and_delay = node.config_gateway.config_set_id_delay(mac, parseInt(config.node_id), parseInt(config.delay));
365
- }
366
- if(config.power_active){
367
- promises.power = node.config_gateway.config_set_power(mac, parseInt(config.power));
368
- }
369
- if(config.retries_active){
370
- promises.retries = node.config_gateway.config_set_retries(mac, parseInt(config.retries));
371
- }
372
- var change_detection = [13, 10, 3];
373
- if(change_detection.indexOf(sensor.type) > -1){
374
- promises.change_detection = node.config_gateway.config_set_change_detection(mac, config.change_enabled ? 1 : 0, parseInt(config.change_pr), parseInt(config.change_interval));
375
- }
376
- switch(sensor.type){
377
- case 5:
378
- promises.acceleration_range = node.config_gateway.config_set_amgt_accel(mac, parseInt(config.amgt_accel));
379
- promises.magnetometer_gain = node.config_gateway.config_set_amgt_magnet(mac, parseInt(config.amgt_mag));
380
- promises.gyroscope_scale = node.config_gateway.config_set_amgt_gyro(mac, parseInt(config.amgt_gyro));
381
- break;
382
- case 6:
383
- promises.altitude = node.config_gateway.config_set_bp_altitude(mac, parseInt(config.bp_altitude));
384
- promises.pressure = node.config_gateway.config_set_bp_pressure(mac, parseInt(config.bp_pressure));
385
- promises.temp_precision = node.config_gateway.config_set_bp_temp_precision(mac, parseInt(config.bp_temp_prec));
386
- promises.pressure_precision = node.config_gateway.config_set_bp_press_precision(mac, parseInt(config.bp_press_prec));
387
- break;
388
- case 7:
389
- promises.acceleration_range = node.config_gateway.config_set_impact_accel(mac, parseInt(config.impact_accel));
390
- promises.data_rate = node.config_gateway.config_set_impact_data_rate(mac, parseInt(config.impact_data_rate));
391
- promises.impact_threshold = node.config_gateway.config_set_impact_threshold(mac, parseInt(config.impact_threshold));
392
- promises.impact_duration = node.config_gateway.config_set_impact_duration(mac, parseInt(config.impact_duration));
393
- break;
394
- case 13:
395
- var cali = parseFloat(config.cm_calibration);
396
- if(cali == 0) break;
397
- promises.calibration = node.config_gateway.config_set_cm_calibration(mac, cali);
398
- break;
399
- case 14:
400
- if(config.sensor_boot_time_420ma_active){
401
- promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
402
- }
403
- break;
404
- case 24:
405
- var interr = parseInt(config.activ_interr_x) | parseInt(config.activ_interr_y) | parseInt(config.activ_interr_z) | parseInt(config.activ_interr_op);
406
- promises.activity_interrupt = node.config_gateway.config_set_activ_interr(mac, interr);
407
- case 35:
408
- if(config.counter_threshold_35_active){
409
- promises.config_set_counter_threshold_35 = node.config_gateway.config_set_counter_threshold_35(mac, parseInt(config.counter_threshold_35));
410
- }
411
- break;
412
- case 36:
413
- if(config.counter_threshold_35_active){
414
- promises.config_set_counter_threshold_35 = node.config_gateway.config_set_counter_threshold_35(mac, parseInt(config.counter_threshold_35));
415
- }
416
- break;
417
- case 40:
418
- promises.filtering = node.config_gateway.config_set_filtering(mac, parseInt(config.filtering));
419
- promises.data_rate = node.config_gateway.config_set_data_rate(mac, parseInt(config.data_rate));
420
- promises.time_series = node.config_gateway.config_set_time_series(mac, parseInt(config.time_series));
421
- promises.reading_type = node.config_gateway.config_set_reading_type(mac, parseInt(config.reading_type));
422
- break;
423
- case 44:
424
- if(config.force_calibration_co2_auto_config){
425
- promises.sensor_forced_calibration = node.config_gateway.config_set_sensor_forced_calibration(mac, parseInt(config.force_calibration_co2));
426
- }
427
- break;
428
- case 45:
429
- if(config.sensor_boot_time_420ma_active){
430
- promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
431
- }
432
- break;
284
+ promises.finish = new Promise((fulfill, reject) => {
285
+ node.config_gateway.queue.add(() => {
286
+ return new Promise((f, r) => {
287
+ clearTimeout(tout);
288
+ node.status(modes.FLY);
289
+ fulfill();
290
+ f();
291
+ });
292
+ });
293
+ });
294
+ for(var i in promises){
295
+ (function(name){
296
+ promises[name].then((f) => {
297
+ if(name != 'finish') msg[name] = true;
298
+ else{
299
+ // #OTF
300
+ this.gateway.fly_101_in_progress = false;
301
+ node.send({topic: 'RTC Broadcast', payload: msg, time: Date.now()});
302
+ top_fulfill(msg);
303
+ }
304
+ }).catch((err) => {
305
+ msg[name] = err;
306
+ });
307
+ })(i);
308
+ }
309
+ });
310
+ });
311
+ }
312
+ function _config(sensor, otf = false){
313
+ return new Promise((top_fulfill, top_reject) => {
314
+ var success = {};
315
+ setTimeout(() => {
316
+ var tout = setTimeout(() => {
317
+ node.status(modes.PGM_ERR);
318
+ node.send({topic: 'Config Results', payload: success, time: Date.now()});
319
+ }, 60000);
320
+ node.status(modes.PGM_NOW);
321
+ if(parseInt(config.sensor_type) >= 10000){
322
+ if(sensor) return;
323
+ var dest = parseInt(config.destination, 16);
324
+ if(dest == 65535){
325
+ dest = [0,0,0,0,0,0,255,255];
326
+ }else{
327
+ dest = [0, 0x13, 0xa2, 0, ...int2Bytes(dest, 4)];
328
+ }
329
+ var promises = {
330
+ destination: node.gateway.config_powered_device(config.addr, 'destination', ...dest),
331
+ network_id: node.gateway.config_powered_device(config.addr, 'network_id', ...int2Bytes(parseInt(config.pan_id, 16), 2)),
332
+ power: node.gateway.config_powered_device(config.addr, 'power', parseInt(config.power)),
333
+ retries: node.gateway.config_powered_device(config.addr, 'retries', parseInt(config.retries)),
334
+ node_id: node.gateway.config_powered_device(config.addr, 'node_id', parseInt(config.node_id)),
335
+ delay: node.gateway.config_powered_device(config.addr, 'delay', ...int2Bytes(parseInt(config.delay), 2))
336
+ };
337
+ }else{
338
+ var mac = sensor.mac;
339
+ var promises = {};
340
+ var reboot = false;
341
+ if(config.form_network){
342
+ promises.establish_config_network_1 = node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF');
343
+ promises.establish_config_network_2 = node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF');
344
+ promises.establish_config_network_3 = node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF');
345
+ }
346
+ if(config.destination_active){
347
+ promises.destination = node.config_gateway.config_set_destination(mac, parseInt(config.destination, 16));
348
+ }
349
+ if(config.pan_id_active){
350
+ reboot = true;
351
+ promises.network_id = node.config_gateway.config_set_pan_id(mac, parseInt(config.pan_id, 16));
352
+ }
353
+ // var promises = {
354
+ // // NOTE: establish_config_network_x commands added to force XBee network to form before sending commands.
355
+ // establish_config_network_1: node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF'),
356
+ // establish_config_network_2: node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF'),
357
+ // establish_config_network_3: node.config_gateway.config_get_pan_id('00:00:00:00:00:00:FF:FF'),
358
+ //
359
+ // destination: node.config_gateway.config_set_destination(mac, parseInt(config.destination, 16)),
360
+ // network_id: node.config_gateway.config_set_pan_id(mac, parseInt(config.pan_id, 16))
361
+ // };
362
+ if(config.node_id_delay_active){
363
+ promises.id_and_delay = node.config_gateway.config_set_id_delay(mac, parseInt(config.node_id), parseInt(config.delay));
364
+ }
365
+ if(config.power_active){
366
+ promises.power = node.config_gateway.config_set_power(mac, parseInt(config.power));
367
+ }
368
+ if(config.retries_active){
369
+ promises.retries = node.config_gateway.config_set_retries(mac, parseInt(config.retries));
370
+ }
371
+ var change_detection = [13, 10, 3];
372
+ if(change_detection.indexOf(sensor.type) > -1){
373
+ promises.change_detection = node.config_gateway.config_set_change_detection(mac, config.change_enabled ? 1 : 0, parseInt(config.change_pr), parseInt(config.change_interval));
374
+ }
375
+ switch(sensor.type){
376
+ case 3:
377
+ if(config.low_calibration_420ma_active){
378
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
379
+ }
380
+ if(config.mid_calibration_420ma_active){
381
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
382
+ }
383
+ if(config.high_calibration_420ma_active){
384
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
385
+ }
386
+ break;
387
+ case 5:
388
+ promises.acceleration_range = node.config_gateway.config_set_amgt_accel(mac, parseInt(config.amgt_accel));
389
+ promises.magnetometer_gain = node.config_gateway.config_set_amgt_magnet(mac, parseInt(config.amgt_mag));
390
+ promises.gyroscope_scale = node.config_gateway.config_set_amgt_gyro(mac, parseInt(config.amgt_gyro));
391
+ break;
392
+ case 6:
393
+ promises.altitude = node.config_gateway.config_set_bp_altitude(mac, parseInt(config.bp_altitude));
394
+ promises.pressure = node.config_gateway.config_set_bp_pressure(mac, parseInt(config.bp_pressure));
395
+ promises.temp_precision = node.config_gateway.config_set_bp_temp_precision(mac, parseInt(config.bp_temp_prec));
396
+ promises.pressure_precision = node.config_gateway.config_set_bp_press_precision(mac, parseInt(config.bp_press_prec));
397
+ break;
398
+ case 7:
399
+ promises.acceleration_range = node.config_gateway.config_set_impact_accel(mac, parseInt(config.impact_accel));
400
+ promises.data_rate = node.config_gateway.config_set_impact_data_rate(mac, parseInt(config.impact_data_rate));
401
+ promises.impact_threshold = node.config_gateway.config_set_impact_threshold(mac, parseInt(config.impact_threshold));
402
+ promises.impact_duration = node.config_gateway.config_set_impact_duration(mac, parseInt(config.impact_duration));
403
+ break;
404
+ case 13:
405
+ var cali = parseFloat(config.cm_calibration);
406
+ if(cali == 0) break;
407
+ promises.calibration = node.config_gateway.config_set_cm_calibration(mac, cali);
408
+ break;
409
+ case 14:
410
+ if(config.sensor_boot_time_420ma_active){
411
+ promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
412
+ }
413
+ if(config.low_calibration_420ma_active){
414
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
415
+ }
416
+ if(config.mid_calibration_420ma_active){
417
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
418
+ }
419
+ if(config.high_calibration_420ma_active){
420
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
421
+ }
422
+ break;
423
+ case 24:
424
+ var interr = parseInt(config.activ_interr_x) | parseInt(config.activ_interr_y) | parseInt(config.activ_interr_z) | parseInt(config.activ_interr_op);
425
+ promises.activity_interrupt = node.config_gateway.config_set_activ_interr(mac, interr);
426
+ case 35:
427
+ if(config.counter_threshold_35_active){
428
+ promises.config_set_counter_threshold_35 = node.config_gateway.config_set_counter_threshold_35(mac, parseInt(config.counter_threshold_35));
429
+ }
430
+ break;
431
+ case 36:
432
+ if(config.counter_threshold_35_active){
433
+ promises.config_set_counter_threshold_35 = node.config_gateway.config_set_counter_threshold_35(mac, parseInt(config.counter_threshold_35));
434
+ }
435
+ break;
436
+ case 40:
437
+ promises.filtering = node.config_gateway.config_set_filtering(mac, parseInt(config.filtering));
438
+ promises.data_rate = node.config_gateway.config_set_data_rate(mac, parseInt(config.data_rate));
439
+ promises.time_series = node.config_gateway.config_set_time_series(mac, parseInt(config.time_series));
440
+ promises.reading_type = node.config_gateway.config_set_reading_type(mac, parseInt(config.reading_type));
441
+ break;
442
+ case 44:
443
+ if(config.force_calibration_co2_auto_config){
444
+ promises.sensor_forced_calibration = node.config_gateway.config_set_sensor_forced_calibration(mac, parseInt(config.force_calibration_co2));
445
+ }
446
+ break;
447
+ case 45:
448
+ if(config.sensor_boot_time_420ma_active){
449
+ promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
450
+ }
451
+ if(config.low_calibration_420ma_active){
452
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
453
+ }
454
+ if(config.mid_calibration_420ma_active){
455
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
456
+ }
457
+ if(config.high_calibration_420ma_active){
458
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
459
+ }
460
+ break;
433
461
  case 46:
434
462
  if(config.motion_threshold_46_active){
435
463
  promises.motion_threshold_46 = node.config_gateway.config_set_motion_threshold_46(mac, parseInt(config.motion_threshold_46));
436
464
  }
437
465
  break;
438
- case 47:
439
- if(config.roll_angle_threshold_47_active){
440
- promises.roll_angle_threshold_47 = node.config_gateway.config_set_roll_threshold_47(mac, parseInt(config.roll_angle_threshold_47));
441
- }
442
- if(config.pitch_angle_threshold_47_active){
443
- promises.pitch_angle_threshold_47 = node.config_gateway.config_set_pitch_threshold_47(mac, parseInt(config.pitch_angle_threshold_47));
444
- }
445
- break;
446
- case 48:
447
- if(config.sensor_boot_time_420ma_active){
448
- promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
449
- }
450
- break;
451
- case 52:
452
- if(config.sensor_boot_time_420ma_active){
453
- promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
454
- }
455
- break;
456
- case 80:
457
- if(config.current_calibration_c1_80_active){
458
- promises.current_calibration_c1_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
459
- }
460
- if(config.output_data_rate_101_active){
461
- promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
462
- }
463
- if(config.sampling_duration_101_active){
464
- promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
465
- }
466
- if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
467
- 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);
468
- }
469
- if(config.sampling_interval_101_active){
470
- promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
471
- }
472
- if(config.full_scale_range_101_active){
473
- promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
474
- }
475
- if(config.mode_80_active){
476
- promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
477
- }
478
- if(config.filter_80_active){
479
- promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
480
- }
481
- if(config.low_pass_filter_80_active){
482
- promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
483
- }
484
- if(config.high_pass_filter_80_active){
485
- promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
486
- }
487
- if(config.measurement_mode_80_active){
488
- promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
489
- }
490
- if(config.on_request_timeout_80_active){
491
- promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
492
- }
493
- if(config.deadband_80_active){
494
- promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
495
- }
496
- if(config.payload_length_80_active){
497
- promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
498
- }
499
- if(config.set_rtc_101){
500
- promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
501
- }
502
- break;
503
- case 81:
504
- if(config.current_calibration_c1_80_active){
505
- promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
506
- }
507
- if(config.current_calibration_c2_80_active){
508
- promises.current_calibration_c2_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c2_80), 3);
509
- }
510
- if(config.output_data_rate_p1_81_active){
511
- promises.output_data_rate_p1_81 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_p1_81));
512
- }
513
- if(config.output_data_rate_p2_81_active){
514
- promises.output_data_rate_p2_81 = node.config_gateway.config_set_output_data_rate_p2_81(mac, parseInt(config.output_data_rate_p2_81));
515
- }
516
- if(config.sampling_duration_p1_81_active){
517
- promises.sampling_duration_p1_81 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_p1_81));
518
- }
519
- if(config.sampling_duration_p2_81_active){
520
- promises.sampling_duration_p2_81 = node.config_gateway.config_set_sampling_duration_p2_81(mac, parseInt(config.sampling_duration_p2_81));
521
- }
522
- if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
523
- 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);
524
- }
525
- if(config.sampling_interval_101_active){
526
- promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
527
- }
528
- if(config.full_scale_range_101_active){
529
- promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
530
- }
531
- if(config.mode_80_active){
532
- promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
533
- }
534
- if(config.filter_80_active){
535
- promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
536
- }
537
- if(config.low_pass_filter_80_active){
538
- promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
539
- }
540
- if(config.high_pass_filter_80_active){
541
- promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
542
- }
543
- if(config.low_pass_filter_81_p2_active){
544
- promises.low_pass_filter_p2 = node.config_gateway.config_set_low_pass_filter_81_p2(mac, parseInt(config.low_pass_filter_81_p2));
545
- }
546
- if(config.high_pass_filter_81_p2_active){
547
- promises.high_pass_filter_p2 = node.config_gateway.config_set_high_pass_filter_81_p2(mac, parseInt(config.high_pass_filter_81_p2));
548
- }
549
- if(config.measurement_mode_80_active){
550
- promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
551
- }
552
- if(config.on_request_timeout_80_active){
553
- promises.on_request_timeout = node.config_gateway.config_set_on_request_timeout_80(mac, parseInt(config.on_request_timeout_80));
554
- }
555
- if(config.deadband_80_active){
556
- promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
557
- }
558
- if(config.payload_length_80_active){
559
- promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
560
- }
561
- if(config.set_rtc_101){
562
- promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
563
- }
564
- break;
565
- case 82:
566
- if(config.current_calibration_82_active){
567
- promises.current_calibration_82 = node.config_gateway.config_set_current_calibration_82(mac, parseInt(config.current_calibration_82));
568
- }
569
- if(config.output_data_rate_101_active){
570
- promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
571
- }
572
- if(config.sampling_duration_101_active){
573
- promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
574
- }
575
- if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
576
- 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);
577
- }
578
- if(config.sampling_interval_101_active){
579
- promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
580
- }
581
- if(config.full_scale_range_101_active){
582
- promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
583
- }
584
- if(config.mode_80_active){
585
- promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
586
- }
587
- if(config.filter_80_active){
588
- promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
589
- }
590
- if(config.low_pass_filter_80_active){
591
- promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
592
- }
593
- if(config.high_pass_filter_80_active){
594
- promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
595
- }
596
- if(config.measurement_mode_80_active){
597
- promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
598
- }
599
- if(config.on_request_timeout_80_active){
600
- promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
601
- }
602
- if(config.deadband_80_active){
603
- promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
604
- }
605
- if(config.payload_length_80_active){
606
- promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
607
- }
608
- if(config.set_rtc_101){
609
- promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
610
- }
611
- break;
612
- case 84:
613
- if(config.output_data_rate_101_active){
614
- promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
615
- }
616
- if(config.sampling_duration_101_active){
617
- promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
618
- }
619
- if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
620
- 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);
621
- }
622
- if(config.sampling_interval_101_active){
623
- promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
624
- }
625
- if(config.full_scale_range_101_active){
626
- promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
627
- }
628
- if(config.mode_80_active){
629
- promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
630
- }
631
- if(config.filter_80_active){
632
- promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
633
- }
634
- if(config.low_pass_filter_80_active){
635
- promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
636
- }
637
- if(config.high_pass_filter_80_active){
638
- promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
639
- }
640
- if(config.measurement_mode_80_active){
641
- promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
642
- }
643
- if(config.on_request_timeout_80_active){
644
- promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
645
- }
646
- if(config.deadband_80_active){
647
- promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
648
- }
649
- if(config.led_alert_mode_84_active){
650
- promises.led_alert_mode_84 = node.config_gateway.config_set_led_alert_mode_84(mac, parseInt(config.led_alert_mode_84));
651
- }
652
- if(config.led_accelerometer_threshold_84_active){
653
- promises.led_accelerometer_threshold_84 = node.config_gateway.config_set_led_accelerometer_threshold_84(mac, parseInt(config.led_accelerometer_threshold_84));
654
- }
655
- if(config.led_velocity_threshold_84_active){
656
- promises.led_velocity_threshold_84 = node.config_gateway.config_set_led_velocity_threshold_84(mac, parseInt(config.led_velocity_threshold_84));
657
- }
658
- if(config.acceleration_interrupt_threshold_84_active){
659
- promises.acceleration_interrupt_threshold_84 = node.config_gateway.config_set_acceleration_interrupt_threshold_84(mac, parseInt(config.acceleration_interrupt_threshold_84));
660
- }
661
- if(config.payload_length_80_active){
662
- promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
663
- }
664
- if(config.set_rtc_101){
665
- promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
666
- }
667
- break;
668
- case 101:
669
- if(config.output_data_rate_101_m2_active){
670
- promises.output_data_rate_101_m2 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101_m2));
671
- }
672
- if(config.sampling_duration_101_active){
673
- promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
674
- }
675
- if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
676
- 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);
677
- }
678
- if(config.sampling_interval_101_active){
679
- promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
680
- }
681
- if(config.full_scale_range_101_m2_active){
682
- promises.full_scale_range_101_m2 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101_m2));
683
- }
684
- // promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
685
- break;
686
- case 102:
687
- if(config.output_data_rate_101_active){
688
- promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
689
- }
690
- if(config.sampling_duration_101_active){
691
- promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
692
- }
466
+ case 47:
467
+ if(config.roll_angle_threshold_47_active){
468
+ promises.roll_angle_threshold_47 = node.config_gateway.config_set_roll_threshold_47(mac, parseInt(config.roll_angle_threshold_47));
469
+ }
470
+ if(config.pitch_angle_threshold_47_active){
471
+ promises.pitch_angle_threshold_47 = node.config_gateway.config_set_pitch_threshold_47(mac, parseInt(config.pitch_angle_threshold_47));
472
+ }
473
+ break;
474
+ case 48:
475
+ if(config.sensor_boot_time_420ma_active){
476
+ promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
477
+ }
478
+ if(config.low_calibration_420ma_active){
479
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
480
+ }
481
+ if(config.mid_calibration_420ma_active){
482
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
483
+ }
484
+ if(config.high_calibration_420ma_active){
485
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
486
+ }
487
+ break;
488
+ case 52:
489
+ if(config.sensor_boot_time_420ma_active){
490
+ promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
491
+ }
492
+ if(config.low_calibration_420ma_active){
493
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
494
+ }
495
+ if(config.mid_calibration_420ma_active){
496
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
497
+ }
498
+ if(config.high_calibration_420ma_active){
499
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
500
+ }
501
+ break;
502
+ case 80:
503
+ if(config.current_calibration_c1_80_active){
504
+ promises.current_calibration_c1_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
505
+ }
506
+ if(config.output_data_rate_101_active){
507
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
508
+ }
509
+ if(config.sampling_duration_101_active){
510
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
511
+ }
512
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
513
+ 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);
514
+ }
515
+ if(config.sampling_interval_101_active){
516
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
517
+ }
518
+ if(config.full_scale_range_101_active){
519
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
520
+ }
521
+ if(config.mode_80_active){
522
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
523
+ }
524
+ if(config.filter_80_active){
525
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
526
+ }
527
+ if(config.low_pass_filter_80_active){
528
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
529
+ }
530
+ if(config.high_pass_filter_80_active){
531
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
532
+ }
533
+ if(config.measurement_mode_80_active){
534
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
535
+ }
536
+ if(config.on_request_timeout_80_active){
537
+ promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
538
+ }
539
+ if(config.deadband_80_active){
540
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
541
+ }
542
+ if(config.payload_length_80_active){
543
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
544
+ }
545
+ if(config.set_rtc_101){
546
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
547
+ }
548
+ break;
549
+ case 81:
550
+ if(config.current_calibration_c1_80_active){
551
+ promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
552
+ }
553
+ if(config.current_calibration_c2_80_active){
554
+ promises.current_calibration_c2_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c2_80), 3);
555
+ }
556
+ if(config.output_data_rate_p1_81_active){
557
+ promises.output_data_rate_p1_81 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_p1_81));
558
+ }
559
+ if(config.output_data_rate_p2_81_active){
560
+ promises.output_data_rate_p2_81 = node.config_gateway.config_set_output_data_rate_p2_81(mac, parseInt(config.output_data_rate_p2_81));
561
+ }
562
+ if(config.sampling_duration_p1_81_active){
563
+ promises.sampling_duration_p1_81 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_p1_81));
564
+ }
565
+ if(config.sampling_duration_p2_81_active){
566
+ promises.sampling_duration_p2_81 = node.config_gateway.config_set_sampling_duration_p2_81(mac, parseInt(config.sampling_duration_p2_81));
567
+ }
568
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
569
+ 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);
570
+ }
571
+ if(config.sampling_interval_101_active){
572
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
573
+ }
574
+ if(config.full_scale_range_101_active){
575
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
576
+ }
577
+ if(config.mode_80_active){
578
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
579
+ }
580
+ if(config.filter_80_active){
581
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
582
+ }
583
+ if(config.low_pass_filter_80_active){
584
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
585
+ }
586
+ if(config.high_pass_filter_80_active){
587
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
588
+ }
589
+ if(config.low_pass_filter_81_p2_active){
590
+ promises.low_pass_filter_p2 = node.config_gateway.config_set_low_pass_filter_81_p2(mac, parseInt(config.low_pass_filter_81_p2));
591
+ }
592
+ if(config.high_pass_filter_81_p2_active){
593
+ promises.high_pass_filter_p2 = node.config_gateway.config_set_high_pass_filter_81_p2(mac, parseInt(config.high_pass_filter_81_p2));
594
+ }
595
+ if(config.measurement_mode_80_active){
596
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
597
+ }
598
+ if(config.on_request_timeout_80_active){
599
+ promises.on_request_timeout = node.config_gateway.config_set_on_request_timeout_80(mac, parseInt(config.on_request_timeout_80));
600
+ }
601
+ if(config.deadband_80_active){
602
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
603
+ }
604
+ if(config.payload_length_80_active){
605
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
606
+ }
607
+ if(config.set_rtc_101){
608
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
609
+ }
610
+ break;
611
+ case 82:
612
+ if(config.current_calibration_82_active){
613
+ promises.current_calibration_82 = node.config_gateway.config_set_current_calibration_82(mac, parseInt(config.current_calibration_82));
614
+ }
615
+ if(config.output_data_rate_101_active){
616
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
617
+ }
618
+ if(config.sampling_duration_101_active){
619
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
620
+ }
621
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
622
+ 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);
623
+ }
624
+ if(config.sampling_interval_101_active){
625
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
626
+ }
627
+ if(config.full_scale_range_101_active){
628
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
629
+ }
630
+ if(config.mode_80_active){
631
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
632
+ }
633
+ if(config.filter_80_active){
634
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
635
+ }
636
+ if(config.low_pass_filter_80_active){
637
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
638
+ }
639
+ if(config.high_pass_filter_80_active){
640
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
641
+ }
642
+ if(config.measurement_mode_80_active){
643
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
644
+ }
645
+ if(config.on_request_timeout_80_active){
646
+ promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
647
+ }
648
+ if(config.deadband_80_active){
649
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
650
+ }
651
+ if(config.payload_length_80_active){
652
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
653
+ }
654
+ if(config.set_rtc_101){
655
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
656
+ }
657
+ break;
658
+ case 84:
659
+ if(config.output_data_rate_101_active){
660
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
661
+ }
662
+ if(config.sampling_duration_101_active){
663
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
664
+ }
665
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
666
+ 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);
667
+ }
668
+ if(config.sampling_interval_101_active){
669
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
670
+ }
671
+ if(config.full_scale_range_101_active){
672
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
673
+ }
674
+ if(config.mode_80_active){
675
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
676
+ }
677
+ if(config.filter_80_active){
678
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
679
+ }
680
+ if(config.low_pass_filter_80_active){
681
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
682
+ }
683
+ if(config.high_pass_filter_80_active){
684
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
685
+ }
686
+ if(config.measurement_mode_80_active){
687
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
688
+ }
689
+ if(config.on_request_timeout_80_active){
690
+ promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
691
+ }
692
+ if(config.deadband_80_active){
693
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
694
+ }
695
+ if(config.led_alert_mode_84_active){
696
+ promises.led_alert_mode_84 = node.config_gateway.config_set_led_alert_mode_84(mac, parseInt(config.led_alert_mode_84));
697
+ }
698
+ if(config.led_accelerometer_threshold_84_active){
699
+ promises.led_accelerometer_threshold_84 = node.config_gateway.config_set_led_accelerometer_threshold_84(mac, parseInt(config.led_accelerometer_threshold_84));
700
+ }
701
+ if(config.led_velocity_threshold_84_active){
702
+ promises.led_velocity_threshold_84 = node.config_gateway.config_set_led_velocity_threshold_84(mac, parseInt(config.led_velocity_threshold_84));
703
+ }
704
+ if(config.acceleration_interrupt_threshold_84_active){
705
+ promises.acceleration_interrupt_threshold_84 = node.config_gateway.config_set_acceleration_interrupt_threshold_84(mac, parseInt(config.acceleration_interrupt_threshold_84));
706
+ }
707
+ if(config.payload_length_80_active){
708
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
709
+ }
710
+ if(config.set_rtc_101){
711
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
712
+ }
713
+ break;
714
+ case 89:
715
+ if(config.sensor_boot_time_420ma_active){
716
+ promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
717
+ }
718
+ if(config.low_calibration_420ma_active){
719
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
720
+ }
721
+ if(config.mid_calibration_420ma_active){
722
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
723
+ }
724
+ if(config.high_calibration_420ma_active){
725
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
726
+ }
727
+ break;
728
+ case 101:
729
+ if(config.output_data_rate_101_m2_active){
730
+ promises.output_data_rate_101_m2 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101_m2));
731
+ }
732
+ if(config.sampling_duration_101_active){
733
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
734
+ }
735
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
736
+ 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);
737
+ }
738
+ if(config.sampling_interval_101_active){
739
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
740
+ }
741
+ if(config.full_scale_range_101_m2_active){
742
+ promises.full_scale_range_101_m2 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101_m2));
743
+ }
744
+ // promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
745
+ break;
746
+ case 102:
747
+ if(config.output_data_rate_101_active){
748
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
749
+ }
750
+ if(config.sampling_duration_101_active){
751
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
752
+ }
693
753
 
694
- // 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);
695
- if(config.sampling_interval_101_active){
696
- promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
697
- }
698
- // if(config.full_scale_range_101_active){
699
- // promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
700
- // }
701
- // promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
702
- break;
703
- case 505:
704
- if(config.current_calibration_c1_80_active){
705
- promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
706
- }
707
- break;
708
- case 506:
709
- if(config.current_calibration_c1_80_active){
710
- promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
711
- }
712
- if(config.current_calibration_c2_80_active){
713
- promises.current_calibration_c2_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c2_80), 3);
714
- }
715
- if(config.current_calibration_c3_80_active){
716
- promises.current_calibration_c3_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c3_80), 5);
717
- }
718
- break;
719
- case 519:
720
- if(config.output_data_rate_101_active){
721
- promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
722
- }
723
- if(config.sampling_duration_101_active){
724
- promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
725
- }
726
- if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
727
- 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);
728
- }
729
- if(config.sampling_interval_101_active){
730
- promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
731
- }
732
- if(config.full_scale_range_101_active){
733
- promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
734
- }
735
- if(config.mode_80_active){
736
- promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
737
- }
738
- if(config.filter_80_active){
739
- promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
740
- }
741
- if(config.low_pass_filter_80_active){
742
- promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
743
- }
744
- if(config.high_pass_filter_80_active){
745
- promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
746
- }
747
- if(config.measurement_mode_80_active){
748
- promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
749
- }
750
- if(config.on_request_timeout_80_active){
751
- promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
752
- }
753
- if(config.deadband_80_active){
754
- promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
755
- }
756
- if(config.led_alert_mode_84_active){
757
- promises.led_alert_mode_84 = node.config_gateway.config_set_led_alert_mode_84(mac, parseInt(config.led_alert_mode_84));
758
- }
759
- if(config.led_accelerometer_threshold_84_active){
760
- promises.led_accelerometer_threshold_84 = node.config_gateway.config_set_led_accelerometer_threshold_84(mac, parseInt(config.led_accelerometer_threshold_84));
761
- }
762
- if(config.led_velocity_threshold_84_active){
763
- promises.led_velocity_threshold_84 = node.config_gateway.config_set_led_velocity_threshold_84(mac, parseInt(config.led_velocity_threshold_84));
764
- }
765
- if(config.acceleration_interrupt_threshold_84_active){
766
- promises.acceleration_interrupt_threshold_84 = node.config_gateway.config_set_acceleration_interrupt_threshold_84(mac, parseInt(config.acceleration_interrupt_threshold_84));
767
- }
768
- if(config.payload_length_80_active){
769
- promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
770
- }
771
- if(config.set_rtc_101){
772
- promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
773
- }
774
- break;
775
- }
776
- }
777
- // These sensors listed in original_otf_devices use a different OTF code.
778
- let original_otf_devices = [53, 80, 81, 82, 83, 84, 101, 102 , 518, 519, 520];
779
- // If we changed the network ID reboot the sensor to take effect.
780
- // TODO if we add the encryption key command to node-red we need to reboot for it as well.
781
- if(reboot){
782
- promises.reboot_sensor = node.config_gateway.config_reboot_sensor(mac);
783
- } else if(otf){
784
- if(original_otf_devices.includes(sensor.type)){
785
- promises.exit_otn_mode = node.config_gateway.config_exit_otn_mode(mac);
786
- }else{
787
- promises.config_exit_otn_mode_common = node.config_gateway.config_exit_otn_mode_common(mac);
788
- }
789
- }
790
- promises.finish = new Promise((fulfill, reject) => {
791
- node.config_gateway.queue.add(() => {
792
- return new Promise((f, r) => {
793
- clearTimeout(tout);
794
- node.status(modes.READY);
795
- fulfill();
796
- f();
797
- });
798
- });
799
- });
800
- for(var i in promises){
801
- (function(name){
802
- promises[name].then((f) => {
803
- if(name != 'finish') success[name] = true;
804
- else{
805
- // #OTF
806
- node.send({topic: 'Config Results', payload: success, time: Date.now()});
807
- top_fulfill(success);
808
- }
809
- }).catch((err) => {
810
- success[name] = err;
811
- });
812
- })(i);
813
- }
814
- }, 1000);
815
- });
816
- }
817
- node._sensor_config = _config;
818
- if(config.addr){
819
- config.addr = config.addr.toLowerCase();
754
+ // 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);
755
+ if(config.sampling_interval_101_active){
756
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
757
+ }
758
+ // if(config.full_scale_range_101_active){
759
+ // promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
760
+ // }
761
+ // promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
762
+ break;
763
+ case 200:
764
+ if(config.low_calibration_420ma_active){
765
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
766
+ }
767
+ if(config.mid_calibration_420ma_active){
768
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
769
+ }
770
+ if(config.high_calibration_420ma_active){
771
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
772
+ }
773
+ break;
774
+ case 505:
775
+ if(config.current_calibration_c1_80_active){
776
+ promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
777
+ }
778
+ break;
779
+ case 506:
780
+ if(config.current_calibration_c1_80_active){
781
+ promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
782
+ }
783
+ if(config.current_calibration_c2_80_active){
784
+ promises.current_calibration_c2_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c2_80), 3);
785
+ }
786
+ if(config.current_calibration_c3_80_active){
787
+ promises.current_calibration_c3_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c3_80), 5);
788
+ }
789
+ break;
790
+ case 519:
791
+ if(config.output_data_rate_101_active){
792
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
793
+ }
794
+ if(config.sampling_duration_101_active){
795
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
796
+ }
797
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
798
+ 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);
799
+ }
800
+ if(config.sampling_interval_101_active){
801
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
802
+ }
803
+ if(config.full_scale_range_101_active){
804
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
805
+ }
806
+ if(config.mode_80_active){
807
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_80));
808
+ }
809
+ if(config.filter_80_active){
810
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
811
+ }
812
+ if(config.low_pass_filter_80_active){
813
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
814
+ }
815
+ if(config.high_pass_filter_80_active){
816
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
817
+ }
818
+ if(config.measurement_mode_80_active){
819
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
820
+ }
821
+ if(config.on_request_timeout_80_active){
822
+ promises.on_request_timeout = node.config_gateway.config_set_filters_80(mac, parseInt(config.on_request_timeout_80));
823
+ }
824
+ if(config.deadband_80_active){
825
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
826
+ }
827
+ if(config.led_alert_mode_84_active){
828
+ promises.led_alert_mode_84 = node.config_gateway.config_set_led_alert_mode_84(mac, parseInt(config.led_alert_mode_84));
829
+ }
830
+ if(config.led_accelerometer_threshold_84_active){
831
+ promises.led_accelerometer_threshold_84 = node.config_gateway.config_set_led_accelerometer_threshold_84(mac, parseInt(config.led_accelerometer_threshold_84));
832
+ }
833
+ if(config.led_velocity_threshold_84_active){
834
+ promises.led_velocity_threshold_84 = node.config_gateway.config_set_led_velocity_threshold_84(mac, parseInt(config.led_velocity_threshold_84));
835
+ }
836
+ if(config.acceleration_interrupt_threshold_84_active){
837
+ promises.acceleration_interrupt_threshold_84 = node.config_gateway.config_set_acceleration_interrupt_threshold_84(mac, parseInt(config.acceleration_interrupt_threshold_84));
838
+ }
839
+ if(config.payload_length_80_active){
840
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
841
+ }
842
+ if(config.set_rtc_101){
843
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
844
+ }
845
+ break;
846
+ }
847
+ }
848
+ // These sensors listed in original_otf_devices use a different OTF code.
849
+ let original_otf_devices = [53, 80, 81, 82, 83, 84, 101, 102 , 518, 519, 520];
850
+ // If we changed the network ID reboot the sensor to take effect.
851
+ // TODO if we add the encryption key command to node-red we need to reboot for it as well.
852
+ if(reboot){
853
+ promises.reboot_sensor = node.config_gateway.config_reboot_sensor(mac);
854
+ } else if(otf){
855
+ if(original_otf_devices.includes(sensor.type)){
856
+ promises.exit_otn_mode = node.config_gateway.config_exit_otn_mode(mac);
857
+ }else{
858
+ promises.config_exit_otn_mode_common = node.config_gateway.config_exit_otn_mode_common(mac);
859
+ }
860
+ }
861
+ promises.finish = new Promise((fulfill, reject) => {
862
+ node.config_gateway.queue.add(() => {
863
+ return new Promise((f, r) => {
864
+ clearTimeout(tout);
865
+ node.status(modes.READY);
866
+ fulfill();
867
+ f();
868
+ });
869
+ });
870
+ });
871
+ for(var i in promises){
872
+ (function(name){
873
+ promises[name].then((f) => {
874
+ if(name != 'finish') success[name] = true;
875
+ else{
876
+ // #OTF
877
+ node.send({topic: 'Config Results', payload: success, time: Date.now()});
878
+ top_fulfill(success);
879
+ }
880
+ }).catch((err) => {
881
+ success[name] = err;
882
+ });
883
+ })(i);
884
+ }
885
+ }, 1000);
886
+ });
887
+ }
888
+ node._sensor_config = _config;
889
+ if(config.addr){
890
+ config.addr = config.addr.toLowerCase();
820
891
 
821
- RED.nodes.getNode(config.connection).sensor_pool.push(config.addr);
822
- this.gtw_on('sensor_data-'+config.addr, (data) => {
823
- node.status(modes.RUN);
824
- data.modem_mac = this.gateway.modem_mac;
825
- node.send({
826
- topic: 'sensor_data',
827
- data: data,
828
- payload: data.sensor_data,
829
- time: Date.now()
830
- });
831
- });
832
- this.gtw_on('set_destination_address'+config.addr, (d) => {
833
- if(config.auto_config){
834
- node.warn('Setting destination address');
835
- return new Promise((top_fulfill, top_reject) => {
836
- var msg = {};
837
- setTimeout(() => {
838
- var tout = setTimeout(() => {
839
- node.status(modes.PGM_ERR);
840
- node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
841
- }, 10000);
892
+ RED.nodes.getNode(config.connection).sensor_pool.push(config.addr);
893
+ this.gtw_on('sensor_data-'+config.addr, (data) => {
894
+ node.status(modes.RUN);
895
+ data.modem_mac = this.gateway.modem_mac;
896
+ node.send({
897
+ topic: 'sensor_data',
898
+ data: data,
899
+ payload: data.sensor_data,
900
+ time: Date.now()
901
+ });
902
+ });
903
+ this.gtw_on('set_destination_address'+config.addr, (d) => {
904
+ if(config.auto_config){
905
+ node.warn('Setting destination address');
906
+ return new Promise((top_fulfill, top_reject) => {
907
+ var msg = {};
908
+ setTimeout(() => {
909
+ var tout = setTimeout(() => {
910
+ node.status(modes.PGM_ERR);
911
+ node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
912
+ }, 10000);
842
913
 
843
- var promises = {};
914
+ var promises = {};
844
915
 
845
- promises.config_dest_address_fly = node.config_gateway.config_set_destination(d, parseInt(config.destination, 16));
916
+ promises.config_dest_address_fly = node.config_gateway.config_set_destination(d, parseInt(config.destination, 16));
846
917
 
847
- promises.finish = new Promise((fulfill, reject) => {
848
- node.config_gateway.queue.add(() => {
849
- return new Promise((f, r) => {
850
- clearTimeout(tout);
851
- fulfill();
852
- f();
853
- });
854
- });
855
- });
856
- for(var i in promises){
857
- (function(name){
858
- promises[name].then((f) => {
859
- if(name != 'finish') msg[name] = true;
860
- else{
861
- node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
862
- top_fulfill(msg);
863
- }
864
- }).catch((err) => {
865
- msg[name] = err;
866
- });
867
- })(i);
868
- }
869
- });
870
- });
871
- }
872
- });
873
- this.pgm_on('sensor_mode-'+config.addr, (sensor) => {
874
- if(sensor.mode in modes){
875
- node.status(modes[sensor.mode]);
876
- }
877
- else{
878
- console.log('Error: unrecognized sensor mode packet');
879
- }
880
- if(config.auto_config && sensor.mode == "PGM"){
881
- _config(sensor);
882
- }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "FLY"){
883
- // _send_otn_request(sensor);
884
- // Sensors having issues seeing OTN request sent too quickly
885
- // Added timeout to fix issue
886
- var tout = setTimeout(() => {
887
- _send_otn_request(sensor);
888
- }, 100);
889
- }else if(sensor.mode == "FLY" && config.sensor_type == 101 || sensor.mode == "FLY" && config.sensor_type == 102){
890
- // send broadcast rtc to 101 and 102 regardless of settings
891
- if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
892
- var broadcast_tout = setTimeout(() => {
893
- _send_otn_request(sensor);
894
- }, 100);
895
- }
896
- }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "OTN"){
897
- if(config.sensor_type == 101 || config.sensor_type == 102){
898
- if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
899
- this.gateway.fly_101_in_progress = true;
900
- node.warn('start timer 2 ' + Date.now());
901
- var broadcast_tout = setTimeout(() => {
902
- node.warn('broadcast timer expired ' + Date.now());
903
- _broadcast_rtc(sensor);
904
- }, 2000);
905
- }else{
906
- node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
907
- }
908
- if(config.auto_config && config.on_the_fly_enable){
909
- var tout = setTimeout(() => {
910
- node.warn('config timer expired' + Date.now());
911
- _config(sensor, true);
912
- }, 3500);
913
- }
914
- }else{
915
- _config(sensor, true);
916
- }
917
- } else if(config.sensor_type == 101 && sensor.mode == "OTN" || config.sensor_type == 102 && sensor.mode == "OTN"){
918
- if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
919
- this.gateway.fly_101_in_progress = true;
920
- node.warn('start timer 2 ' + Date.now());
921
- var broadcast_tout = setTimeout(() => {
922
- node.warn('broadcast timer expired ' + Date.now());
923
- _broadcast_rtc(sensor);
924
- var otf_timeout = setTimeout(() => {
925
- node.warn('Sending OTF request ' + Date.now());
926
- this.config_gateway.config_exit_otn_mode(sensor.mac);
927
- }, 1000);
928
- }, 2000);
929
- }else{
930
- node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
931
- var otf_timeout = setTimeout(() => {
932
- node.warn('Sending OTF request ' + Date.now());
933
- this.config_gateway.config_exit_otn_mode(sensor.mac);
934
- }, 3000);
935
- }
936
- }
937
- });
938
- }else if(config.sensor_type){
939
- this.gtw_on('sensor_data-'+config.sensor_type, (data) => {
940
- node.status(modes.RUN);
941
- data.modem_mac = this.gateway.modem_mac;
942
- node.send({
943
- topic: 'sensor_data',
944
- data: data,
945
- payload: data.sensor_data,
946
- time: Date.now()
947
- });
948
- });
949
- this.gtw_on('set_destination_address'+config.sensor_type, (d) => {
950
- if(config.auto_config){
951
- node.warn('Setting destination address');
952
- return new Promise((top_fulfill, top_reject) => {
953
- var msg = {};
954
- setTimeout(() => {
955
- var tout = setTimeout(() => {
956
- node.status(modes.PGM_ERR);
957
- node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
958
- }, 10000);
918
+ promises.finish = new Promise((fulfill, reject) => {
919
+ node.config_gateway.queue.add(() => {
920
+ return new Promise((f, r) => {
921
+ clearTimeout(tout);
922
+ fulfill();
923
+ f();
924
+ });
925
+ });
926
+ });
927
+ for(var i in promises){
928
+ (function(name){
929
+ promises[name].then((f) => {
930
+ if(name != 'finish') msg[name] = true;
931
+ else{
932
+ node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
933
+ top_fulfill(msg);
934
+ }
935
+ }).catch((err) => {
936
+ msg[name] = err;
937
+ });
938
+ })(i);
939
+ }
940
+ });
941
+ });
942
+ }
943
+ });
944
+ this.pgm_on('sensor_mode-'+config.addr, (sensor) => {
945
+ if(sensor.mode in modes){
946
+ node.status(modes[sensor.mode]);
947
+ }
948
+ else{
949
+ console.log('Error: unrecognized sensor mode packet');
950
+ }
951
+ if(config.auto_config && sensor.mode == "PGM"){
952
+ _config(sensor);
953
+ }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "FLY"){
954
+ // _send_otn_request(sensor);
955
+ // Sensors having issues seeing OTN request sent too quickly
956
+ // Added timeout to fix issue
957
+ var tout = setTimeout(() => {
958
+ _send_otn_request(sensor);
959
+ }, 100);
960
+ }else if(sensor.mode == "FLY" && config.sensor_type == 101 || sensor.mode == "FLY" && config.sensor_type == 102){
961
+ // send broadcast rtc to 101 and 102 regardless of settings
962
+ if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
963
+ var broadcast_tout = setTimeout(() => {
964
+ _send_otn_request(sensor);
965
+ }, 100);
966
+ }
967
+ }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "OTN"){
968
+ if(config.sensor_type == 101 || config.sensor_type == 102){
969
+ if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
970
+ this.gateway.fly_101_in_progress = true;
971
+ node.warn('start timer 2 ' + Date.now());
972
+ var broadcast_tout = setTimeout(() => {
973
+ node.warn('broadcast timer expired ' + Date.now());
974
+ _broadcast_rtc(sensor);
975
+ }, 2000);
976
+ }else{
977
+ node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
978
+ }
979
+ if(config.auto_config && config.on_the_fly_enable){
980
+ var tout = setTimeout(() => {
981
+ node.warn('config timer expired' + Date.now());
982
+ _config(sensor, true);
983
+ }, 3500);
984
+ }
985
+ }else{
986
+ _config(sensor, true);
987
+ }
988
+ } else if(config.sensor_type == 101 && sensor.mode == "OTN" || config.sensor_type == 102 && sensor.mode == "OTN"){
989
+ if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
990
+ this.gateway.fly_101_in_progress = true;
991
+ node.warn('start timer 2 ' + Date.now());
992
+ var broadcast_tout = setTimeout(() => {
993
+ node.warn('broadcast timer expired ' + Date.now());
994
+ _broadcast_rtc(sensor);
995
+ var otf_timeout = setTimeout(() => {
996
+ node.warn('Sending OTF request ' + Date.now());
997
+ this.config_gateway.config_exit_otn_mode(sensor.mac);
998
+ }, 1000);
999
+ }, 2000);
1000
+ }else{
1001
+ node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
1002
+ var otf_timeout = setTimeout(() => {
1003
+ node.warn('Sending OTF request ' + Date.now());
1004
+ this.config_gateway.config_exit_otn_mode(sensor.mac);
1005
+ }, 3000);
1006
+ }
1007
+ }
1008
+ });
1009
+ }else if(config.sensor_type){
1010
+ this.gtw_on('sensor_data-'+config.sensor_type, (data) => {
1011
+ node.status(modes.RUN);
1012
+ data.modem_mac = this.gateway.modem_mac;
1013
+ node.send({
1014
+ topic: 'sensor_data',
1015
+ data: data,
1016
+ payload: data.sensor_data,
1017
+ time: Date.now()
1018
+ });
1019
+ });
1020
+ this.gtw_on('set_destination_address'+config.sensor_type, (d) => {
1021
+ if(config.auto_config){
1022
+ node.warn('Setting destination address');
1023
+ return new Promise((top_fulfill, top_reject) => {
1024
+ var msg = {};
1025
+ setTimeout(() => {
1026
+ var tout = setTimeout(() => {
1027
+ node.status(modes.PGM_ERR);
1028
+ node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
1029
+ }, 10000);
959
1030
 
960
- var promises = {};
1031
+ var promises = {};
961
1032
 
962
- promises.config_dest_address_fly = node.config_gateway.config_set_destination(d, parseInt(config.destination, 16));
1033
+ promises.config_dest_address_fly = node.config_gateway.config_set_destination(d, parseInt(config.destination, 16));
963
1034
 
964
- promises.finish = new Promise((fulfill, reject) => {
965
- node.config_gateway.queue.add(() => {
966
- return new Promise((f, r) => {
967
- clearTimeout(tout);
968
- fulfill();
969
- f();
970
- });
971
- });
972
- });
973
- for(var i in promises){
974
- (function(name){
975
- promises[name].then((f) => {
976
- if(name != 'finish') msg[name] = true;
977
- else{
978
- node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
979
- top_fulfill(msg);
980
- }
981
- }).catch((err) => {
982
- msg[name] = err;
983
- });
984
- })(i);
985
- }
986
- });
987
- });
988
- }
989
- });
990
- this.pgm_on('sensor_mode', (sensor) => {
991
- if(sensor.type == config.sensor_type){
992
- if(sensor.mode in modes){
993
- node.status(modes[sensor.mode]);
994
- }
995
- else{
996
- console.log('Error: unrecognized sensor mode packet');
997
- }
998
- if(config.auto_config && sensor.mode == 'PGM'){
999
- _config(sensor);
1000
- }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "FLY"){
1001
- // _send_otn_request(sensor);
1002
- // Sensors having issues seeing OTN request sent too quickly
1003
- // Added timeout to fix issue
1004
- var tout = setTimeout(() => {
1005
- _send_otn_request(sensor);
1006
- }, 100);
1007
- }else if(sensor.mode == "FLY" && config.sensor_type == 101 || sensor.mode == "FLY" && config.sensor_type == 102){
1008
- // send broadcast rtc to 101 and 102 regardless of settings
1009
- if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
1010
- var broadcast_tout = setTimeout(() => {
1011
- _send_otn_request(sensor);
1012
- }, 100);
1013
- }
1014
- }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "OTN"){
1015
- if(config.sensor_type == 101 || config.sensor_type == 102){
1016
- if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
1017
- this.gateway.fly_101_in_progress = true;
1018
- node.warn('start timer 2 ' + Date.now());
1019
- var broadcast_tout = setTimeout(() => {
1020
- node.warn('broadcast timer expired ' + Date.now());
1021
- _broadcast_rtc(sensor);
1022
- }, 2000);
1023
- }else{
1024
- node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
1025
- }
1026
- if(config.auto_config && config.on_the_fly_enable){
1027
- var tout = setTimeout(() => {
1028
- node.warn('config timer expired' + Date.now());
1029
- _config(sensor, true);
1030
- }, 3500);
1031
- }
1032
- }else{
1033
- _config(sensor, true);
1034
- }
1035
+ promises.finish = new Promise((fulfill, reject) => {
1036
+ node.config_gateway.queue.add(() => {
1037
+ return new Promise((f, r) => {
1038
+ clearTimeout(tout);
1039
+ fulfill();
1040
+ f();
1041
+ });
1042
+ });
1043
+ });
1044
+ for(var i in promises){
1045
+ (function(name){
1046
+ promises[name].then((f) => {
1047
+ if(name != 'finish') msg[name] = true;
1048
+ else{
1049
+ node.send({topic: 'FLY Set Destination Address', payload: msg, time: Date.now()});
1050
+ top_fulfill(msg);
1051
+ }
1052
+ }).catch((err) => {
1053
+ msg[name] = err;
1054
+ });
1055
+ })(i);
1056
+ }
1057
+ });
1058
+ });
1059
+ }
1060
+ });
1061
+ this.pgm_on('sensor_mode', (sensor) => {
1062
+ if(sensor.type == config.sensor_type){
1063
+ if(sensor.mode in modes){
1064
+ node.status(modes[sensor.mode]);
1065
+ }
1066
+ else{
1067
+ console.log('Error: unrecognized sensor mode packet');
1068
+ }
1069
+ if(config.auto_config && sensor.mode == 'PGM'){
1070
+ _config(sensor);
1071
+ }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "FLY"){
1072
+ // _send_otn_request(sensor);
1073
+ // Sensors having issues seeing OTN request sent too quickly
1074
+ // Added timeout to fix issue
1075
+ var tout = setTimeout(() => {
1076
+ _send_otn_request(sensor);
1077
+ }, 100);
1078
+ }else if(sensor.mode == "FLY" && config.sensor_type == 101 || sensor.mode == "FLY" && config.sensor_type == 102){
1079
+ // send broadcast rtc to 101 and 102 regardless of settings
1080
+ if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
1081
+ var broadcast_tout = setTimeout(() => {
1082
+ _send_otn_request(sensor);
1083
+ }, 100);
1084
+ }
1085
+ }else if(config.auto_config && config.on_the_fly_enable && sensor.mode == "OTN"){
1086
+ if(config.sensor_type == 101 || config.sensor_type == 102){
1087
+ if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
1088
+ this.gateway.fly_101_in_progress = true;
1089
+ node.warn('start timer 2 ' + Date.now());
1090
+ var broadcast_tout = setTimeout(() => {
1091
+ node.warn('broadcast timer expired ' + Date.now());
1092
+ _broadcast_rtc(sensor);
1093
+ }, 2000);
1094
+ }else{
1095
+ node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
1096
+ }
1097
+ if(config.auto_config && config.on_the_fly_enable){
1098
+ var tout = setTimeout(() => {
1099
+ node.warn('config timer expired' + Date.now());
1100
+ _config(sensor, true);
1101
+ }, 3500);
1102
+ }
1103
+ }else{
1104
+ _config(sensor, true);
1105
+ }
1035
1106
 
1036
- }else if(config.sensor_type == 101 && sensor.mode == "OTN" || config.sensor_type == 102 && sensor.mode == "OTN"){
1037
- if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
1038
- this.gateway.fly_101_in_progress = true;
1039
- node.warn('start timer 2 ' + Date.now());
1040
- var broadcast_tout = setTimeout(() => {
1041
- node.warn('broadcast timer expired ' + Date.now());
1042
- _broadcast_rtc(sensor);
1043
- var otf_timeout = setTimeout(() => {
1044
- node.warn('Sending OTF request ' + Date.now());
1045
- this.config_gateway.config_exit_otn_mode(sensor.mac);
1046
- }, 1000);
1047
- }, 2000);
1048
- }else{
1049
- node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
1050
- var otf_timeout = setTimeout(() => {
1051
- node.warn('Sending OTF request ' + Date.now());
1052
- this.config_gateway.config_exit_otn_mode(sensor.mac);
1053
- }, 3000);
1054
- }
1055
- }
1056
- }
1057
- });
1058
- }
1059
- this.on('input', (msg) => {
1060
- if(msg.topic == 'config'){
1061
- _config();
1062
- }else{
1063
- node.gateway.send_arbitrary(config.addr, msg).then((m) => {
1064
- console.log("complete");
1065
- }).catch((err) => {
1066
- console.log("error", err);
1067
- });
1068
- }
1069
- });
1070
- this.on('close', () => {
1071
- for(var e in events){
1072
- node.gateway._emitter.removeAllListeners(e);
1073
- }
1074
- for(var p in pgm_events){
1075
- node.config_gateway._emitter.removeAllListeners(p);
1076
- }
1077
- node.gateway_node.close_comms();
1078
- if(typeof node.config_gateway_node != 'undefined'){
1079
- node.config_gateway_node.close_comms();
1080
- }
1081
- });
1107
+ }else if(config.sensor_type == 101 && sensor.mode == "OTN" || config.sensor_type == 102 && sensor.mode == "OTN"){
1108
+ if(this.gateway.hasOwnProperty('fly_101_in_progress') && this.gateway.fly_101_in_progress == false || !this.gateway.hasOwnProperty('fly_101_in_progress')){
1109
+ this.gateway.fly_101_in_progress = true;
1110
+ node.warn('start timer 2 ' + Date.now());
1111
+ var broadcast_tout = setTimeout(() => {
1112
+ node.warn('broadcast timer expired ' + Date.now());
1113
+ _broadcast_rtc(sensor);
1114
+ var otf_timeout = setTimeout(() => {
1115
+ node.warn('Sending OTF request ' + Date.now());
1116
+ this.config_gateway.config_exit_otn_mode(sensor.mac);
1117
+ }, 1000);
1118
+ }, 2000);
1119
+ }else{
1120
+ node.warn('Attempted to start a new rtc broadcast, but denied rightly at ' + Date.now());
1121
+ var otf_timeout = setTimeout(() => {
1122
+ node.warn('Sending OTF request ' + Date.now());
1123
+ this.config_gateway.config_exit_otn_mode(sensor.mac);
1124
+ }, 3000);
1125
+ }
1126
+ }
1127
+ }
1128
+ });
1129
+ }
1130
+ this.on('input', (msg) => {
1131
+ if(msg.topic == 'config'){
1132
+ _config();
1133
+ }else{
1134
+ node.gateway.send_arbitrary(config.addr, msg).then((m) => {
1135
+ console.log("complete");
1136
+ }).catch((err) => {
1137
+ console.log("error", err);
1138
+ });
1139
+ }
1140
+ });
1141
+ this.on('close', () => {
1142
+ for(var e in events){
1143
+ node.gateway._emitter.removeAllListeners(e);
1144
+ }
1145
+ for(var p in pgm_events){
1146
+ node.config_gateway._emitter.removeAllListeners(p);
1147
+ }
1148
+ node.gateway_node.close_comms();
1149
+ if(typeof node.config_gateway_node != 'undefined'){
1150
+ node.config_gateway_node.close_comms();
1151
+ }
1152
+ });
1082
1153
  }
1083
1154
  RED.nodes.registerType("ncd-wireless-node", NcdWirelessNode);
1084
1155