-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
41 lines (32 loc) · 874 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
'use strict';
/* Magic Mirror
* Module: MMM-DHT-Sensors
*
* By Stefan Krause http://yawns.de
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
var sensor = require('node-dht-sensor');
module.exports = NodeHelper.create({
start: function() {
this.started = false;
this.config = null;
},
readSensor: function() {
var self = this;
var values = sensor.read(this.config.sensorType, this.config.sensorPIN);
if (values.isValid) {
self.sendSocketNotification("DATA", values);
}
setTimeout(function() { self.readSensor(); }, this.config.refreshInterval);
},
socketNotificationReceived: function(notification, payload) {
var self = this;
if (notification === 'CONFIG' && self.started == false) {
self.config = payload;
self.sendSocketNotification("STARTED", true);
self.readSensor();
self.started = true;
}
}
});