-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnode_helper.js
executable file
·54 lines (46 loc) · 1.41 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
44
45
46
47
48
49
50
51
52
53
54
'use strict';
/* Magic Mirror
* Module: MMM-dht22
*
* By Juergen Wolf-Hofer
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
var async = require('async');
var sys = require('sys');
var exec = require('child_process').exec;
module.exports = NodeHelper.create({
start: function() {
console.log('Starting node helper: ' + this.name);
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
var self = this;
if (notification === 'CONFIG') {
this.config = payload;
setInterval(function() {
self.getStats();
}, this.config.updateInterval);
}
},
getStats: function() {
var self = this;
var path = this.config.dht22Util + " ";
async.parallel([
//async.apply(exec, 'sudo /home/pi/bin/dht22 c 22'),
//async.apply(exec, 'sudo /home/pi/bin/dht22 f 22'),
//async.apply(exec, 'sudo /home/pi/bin/dht22 h 22'),
async.apply(exec, this.config.dht22util + ' c ' + this.config.dht22gpio),
async.apply(exec, this.config.dht22util + ' f ' + this.config.dht22gpio),
async.apply(exec, this.config.dht22util + ' h ' + this.config.dht22gpio)
],
function (err, res) {
var stats = {};
stats.celsius = res[0][0];
stats.fahrenheit = res[1][0];
stats.humidity = res[2][0];
//console.log(stats);
self.sendSocketNotification('STATS', stats);
});
},
});