-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode_helper.js
43 lines (36 loc) · 1.02 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-ReadHDC1080
*
* By Michael F.
*
*/
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 HDC1080, read humidity and temp from i2c
exec("sudo ./modules/MMM-HDC1080/ReadHDC1080 " + 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[0],
humidity: arr[1]
});
});
}
}
});