forked from iobroker-community-adapters/ioBroker.rpi2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·765 lines (700 loc) · 28.6 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/**
* RPI-Monitor Adapter
*
* License: MIT
*/
'use strict';
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
let gpio;
let gpioButtons;
let errorsLogged = {};
const debounceTimers = [];
const intervalTimers = [];
// Which button events will we capture and have states for?
// See https://www.npmjs.com/package/rpi-gpio-buttons
const buttonEvents = [ 'pressed', 'clicked', 'clicked_pressed', 'double_clicked', 'released' ];
const adapter = new utils.Adapter({
name: 'rpi2',
ready: function () {
config = adapter.config;
objects = {};
if (adapter.config.forceinit) {
adapter.getAdapterObjects((res) => {
for (const id of Object.keys(res)) {
if (/^rpi2\.\d+$/.test(id)) {
adapter.log.debug('Skip root object ' + id);
continue;
}
adapter.log.debug('Remove ' + id + ': ' + id);
adapter.delObject(id, (res, err) => {
if (res !== undefined && res !== null && res !== 'Not exists') adapter.log.error('res from delObject: ' + res);
if (err !== undefined) adapter.log.error('err from delObject: ' + err);
});
adapter.deleteState(id, (res, err) => {
if (res !== undefined && res !== null && res !== 'Not exists') adapter.log.error('res from deleteState: ' + res);
if (err !== undefined) adapter.log.error('err from deleteState: ' + err);
});
}
adapter.subscribeStates('*');
main();
});
} else {
adapter.getAdapterObjects((res) => {
for (const id of Object.keys(res)) {
objects[id] = true; //object already exists.
}
adapter.log.debug('received all objects');
adapter.subscribeStates('*');
main();
});
}
},
stateChange: function (id, state) {
adapter.log.debug('stateChange for ' + id + ' found state = ' + JSON.stringify(state));
if (state && !state.ack) {
if (id.indexOf('gpio.') !== -1) {
const parts = id.split('.');
parts.pop(); // remove state
writeGpio(parts.pop(), state.val);
}
}
},
unload: async function () {
// Cancel any intervals
for (const interval of intervalTimers) {
clearInterval(interval);
}
// Cancel any debounce timers
for (const timer of debounceTimers) {
if (timer != null) {
clearTimeout(timer);
}
};
if (gpio) {
if (gpioButtons) {
await gpioButtons.destroy().catch((err) => {
console.error(`Failed to destroy gpioButtons: ${err}`);
});
};
await gpio.promise.destroy().catch((err) => {
console.error(`Failed to destroy gpio: ${err}`);
});
}
}
});
function writeGpio(port, value) {
port = parseInt(port, 10);
if (!adapter.config.gpios[port] || !adapter.config.gpios[port].enabled) {
adapter.log.warn('Port ' + port + ' is not writable, because disabled.');
return;
} else if (adapter.config.gpios[port].input === 'in' || adapter.config.gpios[port].input === 'true' || adapter.config.gpios[port].input === true) {
return adapter.log.warn('Port ' + port + ' is configured as input and not writable');
}
if (value === 'true') value = true;
if (value === 'false') value = false;
if (value === '0') value = false;
value = !!value;
try {
if (gpio) {
gpio.write(port, value, err => {
if (err) {
adapter.log.error(err);
} else {
adapter.log.debug('Written ' + value + ' into port ' + port);
adapter.setState('gpio.' + port + '.state', value, true);
}
});
} else {
adapter.log.error('GPIO is not initialized!');
}
} catch (error) {
adapter.log.error('Cannot write port ' + port + ': ' + error);
}
}
let objects;
let exec;
const rpi = {};
const table = {};
let config;
let oldstyle = false;
function main() {
if (anyParserConfigEnabled()) {
// TODO: Check which Objects we provide
intervalTimers.push(setInterval(parser, adapter.config.interval || 60000));
const version = process.version;
const va = version.split('.');
if (va[0] === 'v0' && va[1] === '10') {
adapter.log.debug('NODE Version = ' + version + ', we need new exec-sync');
exec = require('sync-exec');
oldstyle = true;
} else {
adapter.log.debug('NODE Version = ' + version + ', we need new execSync');
exec = require('child_process').execSync;
}
parser();
} else {
adapter.log.info('No parser items enabled - skipping');
}
initPorts();
}
function anyParserConfigEnabled() {
for (const configKey of Object.keys(adapter.config)) {
if (configKey.indexOf('c_') >= 0) {
adapter.log.debug(`${configKey} looks like a parser item`);
if (adapter.config[configKey] === true) {
adapter.log.debug(`${configKey} is enabled`);
return true;
}
}
}
return false;
}
function parser() {
adapter.log.debug('start parsing');
// Workaround, WebStorm
if (config === undefined) {
config = adapter.config;
}
for (const c in config) {
if (!config.hasOwnProperty(c)) continue;
adapter.log.debug('PARSING: ' + c);
if (c.indexOf('c_') !== 0 && config['c_' + c] === true) {
table[c] = new Array(20);
const o = config[c];
for (const i in o) {
if (!o.hasOwnProperty(i)) continue;
adapter.log.debug(' PARSING: ' + i);
const object = o[i];
const command = object.command;
let regexp;
if (object.multiline !== undefined) {
regexp = new RegExp(object.regexp, 'm');
} else {
regexp = new RegExp(object.regexp);
}
const post = object.post;
adapter.log.debug('---> ' + command);
let stdout;
try {
if (oldstyle) {
stdout = exec(command).stdout;
} else {
stdout = exec(command).toString();
}
adapter.log.debug('------------- ' + stdout);
} catch (er) {
adapter.log.debug(er.stack);
if (er.pid) console.log('%s (pid: %d) exited with status %d',
er.file, er.pid, er.status);
// do not process if exec fails
continue;
}
const match = regexp.exec(stdout);
adapter.log.debug('---> REGEXP: ' + regexp);
if (match !== undefined && match !== null && match.length !== undefined) {
adapter.log.debug('GROUPS: ' + match.length);
}
// TODO: if Group Match is bigger than 2
// split groups and header into separate objects
if (match !== undefined && match !== null && match.length > 2) {
const lname = i.split(',');
for (let m = 1; m < match.length; m++) {
const value = match[m];
const name = lname[m - 1];
adapter.log.debug('MATCHING: ' + value);
adapter.log.debug('NAME: ' + name + ', VALULE: ' + value);
rpi[name] = value;
table[c][i] = value;
}
} else {
adapter.log.debug('---> POST: ' + post);
let value;
if (match !== undefined && match !== null) {
value = match[1];
} else {
value = stdout;
}
rpi[i] = value;
table[c][i] = value;
}
}
}
}
// TODO: Parse twice to get post data and evaluate
for (const c in config) {
if (!config.hasOwnProperty(c)) continue;
adapter.log.debug('CURRENT = ' + c + ' ' + config['c_' + c]);
adapter.log.debug(c.indexOf('c_'));
if (c.indexOf('c_') !== 0 && config['c_' + c]) {
if (objects[c] === undefined) {
const stateObj = {
common: {
name: c, // You can add here some description
role: 'sensor'
},
type: 'device',
_id: c
};
adapter.extendObject(c, stateObj);
objects[c] = true; //remember that we created the object.
}
const o = config[c];
for (const i in o) {
if (!o.hasOwnProperty(i)) {
continue;
}
const object = o[i];
const command = object.command;
const post = object.post;
adapter.log.debug('---> POST: ' + post + ' for ' + i + ' in ' + o);
let value;
const lname = i.split(',');
if (lname !== undefined && lname.length > 1) {
for (let m = 0; m < lname.length; m++) {
const name = lname[m];
value = rpi[name];
// TODO: Check if value is number and format it 2 Digits
if (!isNaN(value)) {
value = parseFloat(value);
const re = new RegExp(/^\d+\.\d+$/);
if (re.exec(value)) {
value = parseFloat(value.toFixed(2));
}
}
adapter.log.debug('MATCHING: ' + value);
adapter.log.debug('NAME: ' + name + ' VALUE: ' + value);
const objectName = adapter.name + '.' + adapter.instance + '.' + c + '.' + name;
adapter.log.debug('SETSTATE FOR ' + objectName + ' VALUE = ' + value);
if (objects[objectName] === undefined) {
// TODO Create an Object tree
const stateObj = {
common: {
name: objectName, // You can add here some description
read: true,
write: false,
state: 'state',
role: 'value',
type: 'number'
},
type: 'state',
_id: objectName
};
adapter.extendObject(objectName, stateObj);
objects[objectName] = true; //remember that we created the object.
}
adapter.setState(objectName, {
val: value,
ack: true
});
}
} else {
value = rpi[i];
if (value !== undefined && value !== '' && value !== null) {
if (post.indexOf('$1') !== -1) {
adapter.log.debug('VALUE: ' + value + ' POST: ' + post);
try {
value = eval(post.replace('$1', value));
} catch (e) {
adapter.log.error('Cannot evaluate: ' + post.replace('$1', value));
value = NaN;
}
}
// TODO: Check if value is number and format it 2 Digits
if (!isNaN(value)) {
value = parseFloat(value);
const r = new RegExp(/^\d+\.\d+$/);
if (r.exec(value)) {
value = parseFloat(value.toFixed(2));
}
}
const objectName = adapter.name + '.' + adapter.instance + '.' + c + '.' + i;
adapter.log.debug('SETSTATE FOR ' + objectName + ' VALUE = ' + value);
if (objects[objectName] === undefined) {
// TODO Create an Objecttree
const stateObj = {
common: {
name: objectName, // You can add here some description
read: true,
write: false,
state: 'state',
role: 'value',
type: 'mixed'
},
type: 'state',
_id: objectName
};
adapter.extendObject(objectName, stateObj);
objects[objectName] = true; //remember that we created the object.
}
adapter.setState(objectName, {
val: value,
ack: true
});
} else {
if (i === 'wifi_send' || i === 'wifi_received') {
adapter.log.debug('No Value found for ' + i);
} else if (! errorsLogged[i]) {
adapter.log.error('No Value found for ' + i);
errorsLogged[i] = true;
}
}
}
}
}
}
}
function inputPullUp(value) {
return (adapter.config.inputPullUp ? !value : value);
}
function readValue(port) {
if (!gpio) {
return adapter.log.error('GPIO is not initialized!');
}
gpio.read(port, (err, value) => {
if (err) {
adapter.log.error('Cannot read port ' + port + ': ' + err);
} else {
adapter.setState('gpio.' + port + '.state', inputPullUp(value), true);
}
});
}
// syncPort waits for everything it calls, so upon return, when the GPIO
// handlers, etc. are setup their states are guaranteed to be in place.
// Our own deleteState that logs an error only if it's not, Not Exists
async function deleteState(stateName) {
try {
await adapter.delObjectAsync(stateName);
} catch (err) {
if (err != 'Error: Not exists') {
throw new Error(`Failed to delete object ${stateName}: ${err}`);
}
}
await deleteObject(stateName);
}
async function deleteObject(objectName) {
try {
await adapter.delStateAsync(objectName);
} catch (err) {
if (err != 'Error: Not exists') {
throw new Error(`Failed to delete object ${objectName}: ${err}`);
}
}
}
async function syncPort(port, data) {
data.isGpio = (data.input === 'in' || data.input === 'out' || data.input === 'outlow' || data.input === 'outhigh');
data.isButton = (data.input === 'button');
data.isTempHum = (data.input === 'dht11' || data.input === 'dht22');
data.isInput = (data.input === 'in' || data.isButton || data.isTempHum);
const channelName = 'gpio.' + port;
if (data.enabled) {
await adapter.extendObjectAsync(channelName, {
type: 'channel',
common: {
name: !data.hasOwnProperty('label') || data.label == '' ? 'GPIO ' + port : data.label,
// TODO: should we do more than just add this as 'info'?
role: 'info'
}
});
}
const stateName = 'gpio.' + port + '.state';
if (data.enabled && data.isGpio) {
const obj = {
common: {
name: 'GPIO ' + port,
type: 'boolean',
role: data.isInput ? 'indicator' : 'switch',
read: data.isInput,
write: !data.isInput
},
native: {
},
type: 'state'
};
// extendObject creates one if it doesn't exist - same below
await adapter.extendObjectAsync(stateName, obj);
} else {
await deleteState(stateName);
}
await syncPortDirection(port, data);
await syncPortButton(port, data);
await syncPortTempHum(port, data);
// Delete the channel only after everything will have been removed or
// we end up with junk in the object tree.
if (!data.enabled) {
await deleteObject(channelName);
}
}
async function syncPortDirection(port, data) {
const stateName = 'gpio.' + port + '.isInput';
if (data.enabled) {
adapter.log.debug(`Creating ${stateName}`);
const obj = {
common: {
name: 'GPIO ' + port + ' direction',
type: 'boolean',
role: 'state',
read: true,
write: false
},
native: {
},
type: 'state'
};
await adapter.extendObjectAsync(stateName, obj);
await adapter.setStateAsync(stateName, data.isInput, true);
} else {
await deleteState(stateName);
}
}
function buttonStateName(port, eventName) {
return 'gpio.' + port + '.' + eventName;
}
async function syncPortButton(port, data) {
for (const eventName of buttonEvents) {
const stateName = buttonStateName(port, eventName);
if (data.enabled && data.isButton) {
const obj = {
common: {
name: 'GPIO ' + port + ' ' + eventName,
type: 'boolean',
role: 'button',
read: false,
write: true
},
native: {
},
type: 'state'
};
await adapter.extendObjectAsync(stateName, obj);
} else {
await deleteState(stateName);
}
};
}
function temperatureStateName(port) {
return 'gpio.' + port + '.temperature';
}
function humidityStateName(port) {
return 'gpio.' + port + '.humidity';
}
async function syncPortTempHum(port, data) {
if (data.enabled && data.isTempHum) {
const obj = {
common: {
name: 'GPIO ' + port + ' temperature',
type: 'number',
role: 'value.temperature',
read: true,
write: false
},
native: {
},
type: 'state'
};
await adapter.extendObjectAsync(temperatureStateName(port), obj);
} else {
await deleteState(temperatureStateName(port));
}
if (data.enabled && data.isTempHum) {
const obj = {
common: {
name: 'GPIO ' + port + ' temperature',
type: 'number',
role: 'value.humidity',
read: true,
write: false
},
native: {
},
type: 'state'
};
await adapter.extendObjectAsync(humidityStateName(port), obj);
} else {
await deleteState(humidityStateName(port));
}
}
// Setup GPIO ports & buttons
function setupGpio(gpioPorts, buttonPorts) {
if (gpioPorts.length == 0 && buttonPorts.length == 0) return;
adapter.log.debug('Inputs are pull ' + (adapter.config.inputPullUp ? 'up' : 'down') + '.');
adapter.log.debug('Buttons are pull ' + (adapter.config.buttonPullUp ? 'up' : 'down') + '.');
try {
gpio = require('rpi-gpio');
gpio.setMode(gpio.MODE_BCM);
} catch (e) {
gpio = null;
adapter.log.error('Cannot initialize/setMode GPIO: ' + e);
}
if (gpio) {
// Our GPIO init worked, setup regular I/O & buttons.
let haveGpioInputs = false;
// Setup all the regular GPIO input and outputs.
for (const port of gpioPorts) {
const direction = adapter.config.gpios[port].input;
adapter.log.debug(`Port ${port} direction: ${direction}`);
if (direction == 'in') {
// Input port
haveGpioInputs = true;
gpio.setup(port, gpio.DIR_IN, gpio.EDGE_BOTH, (err) => {
if (err) {
adapter.log.error('Cannot setup port ' + port + ' as input: ' + err);
} else {
readValue(port);
}
});
} else {
// All the different flavours of output
const directionCode = direction == 'outlow' ? gpio.DIR_LOW : direction == 'outhigh' ? gpio.DIR_HIGH : gpio.DIR_OUT;
adapter.log.debug(`Port ${port} directionCode: ${directionCode}`);
gpio.setup(port, directionCode, (err) => {
err && adapter.log.error('Cannot setup port ' + port + ' as output: ' + err);
});
}
}
// Setup input change handler - only has to be done once no matter how many inputs we have.
if (haveGpioInputs) {
adapter.log.debug('Register onchange handler');
gpio.on('change', (port, value) => {
// Ignore buttons as they are handled below
if (adapter.config.gpios[port].input == 'in') {
adapter.log.debug('GPIO change on port ' + port + ': ' + value);
if (debounceTimers[port] != null) {
// Timer is running but state changed (must be back) so just cancel timer.
clearTimeout(debounceTimers[port]);
debounceTimers[port] = null;
} else {
// Start a timer and report to state if doesn't revert within given period.
debounceTimers[port] = setTimeout((t_port, t_value) => {
debounceTimers[t_port] = null;
adapter.log.debug(`GPIO debounced on port ${t_port}: ${t_value}`);
adapter.setState('gpio.' + t_port + '.state', inputPullUp(t_value), true);
}, adapter.config.inputDebounceMs, port, value);
}
}
});
}
// Setup any buttons using same rpi-gpio object as other I/O.
if (buttonPorts.length > 0) {
adapter.log.debug(`Setting up button ports: ${buttonPorts}`);
try {
const rpi_gpio_buttons = require('rpi-gpio-buttons');
gpioButtons = new rpi_gpio_buttons({
pins: buttonPorts,
usePullUp: adapter.config.buttonPullUp,
timing: {
debounce: adapter.config.buttonDebounceMs,
pressed: adapter.config.buttonPressMs,
clicked: adapter.config.buttonDoubleMs
},
gpio: gpio
});
} catch (e) {
gpioButtons = null;
adapter.log.error('Cannot initialize GPIO Buttons: ' + e);
}
// Setup events for buttons - only has to be done once no matter how many buttons we have.
if (gpioButtons) {
for (const eventName of buttonEvents) {
adapter.log.debug(`Register button handler for ${eventName}`);
gpioButtons.on(eventName, (port) => {
adapter.log.debug(`${eventName} triggered for port ${port}`);
const stateName = buttonStateName(port, eventName);
adapter.setState(stateName, true, true);
});
};
// And start button processing
gpioButtons.init().catch(err => {
adapter.log.error(`An error occurred during buttons init(). ${err.message}`);
});
}
}
}
}
// Setup DHTxx/AM23xx sensors
function setupDht(dhtPorts) {
if (dhtPorts.length == 0) return;
let pollInterval = adapter.config.dhtPollInterval;
if (pollInterval == 0) {
adapter.log.warn('DHTxx/AM23xx configured but polling disabled');
} else if (pollInterval < 350) {
adapter.log.error(`DHTxx/AM23xx polling interval seems too short (${pollInterval}) - disabling`);
} else {
// Config is good
const sensorLib = require('node-dht-sensor');
// Initialise ports, keeping track of those that worked with type
const dhtInitd = [];
for (const port of dhtPorts) {
const type = adapter.config.gpios[port].input == 'dht11' ? 11 : 22;
try {
sensorLib.initialize(type, port);
dhtInitd[port] = [type];
} catch (err) {
adapter.log.error(`Failed to initialise DHTxx/AM23xx: ${type}/${port}`);
}
}
if (dhtInitd.length > 0) {
// At least one initialised, set polling on configured interval
intervalTimers.push(setInterval(() => {
for (const [port, type] of Object.entries(dhtInitd)) {
sensorLib.read(type, port, function(err, temperature, humidity) {
if (err) {
adapter.log.error(`Failed to read DHTxx/AM23xx: ${type}/${port}`);
} else {
adapter.log.debug(`Read DHTxx/AM23xx: ${type}/${port} : ${temperature}°C, humidity: ${humidity}%`);
adapter.setStateChanged(temperatureStateName(port), temperature, true);
adapter.setStateChanged(humidityStateName(port), humidity, true);
}
});
}
}, pollInterval));
}
}
}
async function initPorts() {
if (adapter.config.gpios && adapter.config.gpios.length) {
let gpioPorts = [];
let buttonPorts = [];
let dhtPorts = [];
for (let port = 0; port < adapter.config.gpios.length; port++) {
if (adapter.config.gpios[port]) {
/* Ensure backwards compatibility of property .input
* in older versions, it was true for "in" and false for "out"
* in newer versions, it is "in", "out", "outlow" or "outhigh"
* Do this now so we only have to check for newer versions everywhere else.
*/
if (adapter.config.gpios[port].input === 'true' || adapter.config.gpios[port].input === true) {
adapter.config.gpios[port].input = 'in';
}
else if (adapter.config.gpios[port].input === 'false' || adapter.config.gpios[port].input === false) {
adapter.config.gpios[port].input = 'out';
}
}
// syncPort sets up object tree. Do it now so all ready when
// physical GPIOs are enabled below.
await syncPort(port, adapter.config.gpios[port] || {});
if (!adapter.config.gpios[port] || !adapter.config.gpios[port].enabled) continue;
// Push port numbers into arrays as required for setup below.
switch(adapter.config.gpios[port].input) {
case 'in':
case 'out':
case 'outlow':
case 'outhigh':
gpioPorts.push(port);
break;
case 'button':
buttonPorts.push(port);
break;
case 'dht11':
case 'dht22':
dhtPorts.push(port);
break;
default:
adapter.log.error('Cannot setup port ' + port + ': invalid direction type.');
}
}
setupGpio(gpioPorts, buttonPorts);
setupDht(dhtPorts);
} else {
adapter.log.info('GPIO ports are not configured');
}
}