-
Notifications
You must be signed in to change notification settings - Fork 3
/
node_helper.js
42 lines (37 loc) · 940 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
36
37
38
39
40
41
42
'use strict';
/* Magic Mirror
* Module: MMM-BME280
*
* By Andrew Witwicki
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
const exec = require('child_process').exec;
module.exports = NodeHelper.create({
start: function () {
console.log('BME280 helper started ...');
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function (notification, payload) {
const self = this;
if (notification === 'REQUEST') {
const self = this
this.config = payload
var deviceAddr = this.config.deviceAddress;
// execute external DHT Script
exec(`python3 ./modules/MMM-BME280/bme280.py ${deviceAddr}`, (error, stdout) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
var arr = stdout.split(" ");
// Send data
self.sendSocketNotification('DATA', {
temp: arr[0],
humidity: arr[1],
press: arr[2],
});
});
}
}
});