-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMMM-DHT22.js
59 lines (46 loc) · 1.42 KB
/
MMM-DHT22.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
55
56
57
58
59
Module.register("MMM-DHT22",{
// Default module config.
defaults: {
sensorPIN: 2,
updateInterval: 0.5, // Minutes
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
this.loaded = false;
this.temperature = '';
this.humidity= '';
this.update();
setInterval(
this.update.bind(this),
this.config.updateInterval * 60 * 1000);
},
update: function(){
this.sendSocketNotification('REQUEST', this.config);
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
wrapper.className = "light small";
if (!this.loaded) {
wrapper.innerHTML = "Loading ...";
wrapper.className = "dimmed light small";
return wrapper;
}
var temp = document.createElement("div");
temp.innerHTML = "Temperatur: " + this.temperature + " °C";
wrapper.appendChild(temp);
var hum = document.createElement("div");
hum.innerHTML = "Luftfeuchtigkeit: " + this.humidity + " %";
wrapper.appendChild(hum);
return wrapper;
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'DATA') {
this.temperature = payload.temp;
this.humidity = payload.humidity;
this.loaded = 1;
this.updateDom();
}
},
});