-
Notifications
You must be signed in to change notification settings - Fork 2
/
node_helper.js
43 lines (36 loc) · 1 KB
/
node_helper.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
'use strict';
/* Magic Mirror
* Module: MMM-PIR-Sensor
*
* By Benjamin Angst
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
const exec = require('child_process').exec;
module.exports = NodeHelper.create({
start: function () {
console.log('Temperatur helper started ...');
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
const self = this;
if (notification === 'REQUEST') {
const self = this
this.config = payload
// execute external DHT Script
exec("sudo ./modules/MMM-DHT22/dht_var " + this.config.sensorPIN, (error, stdout) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
var arr = stdout.split(",");
//console.log("Log: " + temp + " - " + hum);
// Send Temperatur
self.sendSocketNotification('DATA',{
temp: arr[1],
humidity: arr[0]
});
});
}
}
});