forked from MichMich/mmm-systemtemperature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
35 lines (28 loc) · 818 Bytes
/
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
var NodeHelper = require("node_helper");
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.sendTemperature();
}, this.config.updateInterval);
}
},
sendTemperature: function() {
var self = this;
child = exec("/opt/vc/bin/vcgencmd measure_temp", function (error, stdout, stderr) {
if (error) {
console.log(error);
return;
}
self.sendSocketNotification('TEMPERATURE', parseFloat(stdout.replace('temp=','')));
});
}
});