-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathnode_helper.js
More file actions
32 lines (28 loc) · 910 Bytes
/
Copy pathnode_helper.js
File metadata and controls
32 lines (28 loc) · 910 Bytes
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
var NodeHelper = require("node_helper");
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) {
if (notification === 'CONFIG') {
this.config = payload;
setInterval(() => {
this.sendTemperature();
}, this.config.updateInterval);
}
},
sendTemperature: function() {
var command = "cat /sys/class/thermal/thermal_zone*/temp"
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(error);
return;
}
var temperatures = stdout.trim().split('\n').map((t) => parseInt(t));
var average = temperatures.reduce((a, b) => a + b, 0) / temperatures.length || 0;
this.sendSocketNotification('TEMPERATURE', (average / 1000).toFixed(2));
});
}
});