-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMMM-dht22.js
executable file
·70 lines (61 loc) · 1.96 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
60
61
62
63
64
65
66
67
68
69
70
/* Magic Mirror
* Module: MMM-dht22
*
* By Juergen Wolf-Hofer
* MIT Licensed.
*/
Module.register('MMM-dht22', {
defaults: {
updateInterval: 10000,
animationSpeed: 0,
header: 'DHT22 Sensor',
tempUnit: 'celsius', // 'celsius' or 'fahrenheit'
dht22gpio: 22,
dht22util: 'sudo /home/pi/bin/dht22'
},
getStyles: function () {
return ["MMM-dht22.css"];
},
// Define start sequence
start: function() {
Log.log('Starting module: ' + this.name);
this.stats = {};
this.stats.celsius = 'reading ...';
this.stats.fahrenheit = 'reading ...';
this.stats.humidity = 'reading ...';
this.sendSocketNotification('CONFIG', this.config);
},
socketNotificationReceived: function(notification, payload) {
//Log.log('MMM-dht22: socketNotificationReceived ' + notification);
//Log.log(payload);
if (notification === 'STATS') {
this.stats.celsius = payload.celsius + '°C';
this.stats.fahrenheit = payload.fahrenheit + '°F';
this.stats.humidity = payload.humidity + '%';
this.updateDom(this.config.animationSpeed);
}
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement('div');
var header = document.createElement("header");
//header.classList.add("align-left");
var name = document.createElement("span");
name.innerHTML = "" + this.config.header;
header.appendChild(name);
wrapper.appendChild(header);
var table = document.createElement('table');
table.classList.add("small", "table");
table.innerHTML = '<tr>' +
'<td class="normal">Temperature: </td>' +
'<td class="bright">' +
((this.config.tempUnit == 'fahrenheit') ? this.stats.fahrenheit : this.stats.celsius) +
'</td>' +
'</tr><tr>' +
'<td class="normal">Humidity: </td>' +
'<td class="bright">' + this.stats.humidity + '</td>' +
'</tr>';
wrapper.appendChild(table);
return wrapper;
},
});