-
Notifications
You must be signed in to change notification settings - Fork 0
/
html.py
99 lines (91 loc) · 2.35 KB
/
html.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
html = """<!DOCTYPE html>
<html>
<style>
body {
font-family: Courier New, Courier, Lucida Sans Typewriter,
Lucida Typewriter, monospace;
color: #222;
margin: 0;
}
h1,
h2,
h3 {
margin: 0 0 0.35em;
}
h1 {
font-size: 40px;
}
h2 {
font-size: 28px;
text-align: center;
}
p {
margin: 0 0 1.15em;
text-align: center;
}
.container {
max-width: 800px;
margin-left: auto;
margin-right: auto;
padding: 24px;
}
header {
background-color: rgb(89, 47, 145);
color: #ffffff;
text-align: center;
}
</style>
<body>
<header id="title">
<div class="container">
<h1>BMP280 Sensor</h1>
</div>
</header>
<div class="container">
<h2>Temperature: <span id="tempValue">None</span> ºC</h2>
</div>
<div class="container">
<h2>Pressure: <span id="pressureValue">None</span> pa</h2>
</div>
<div class="container">
<p>Source: <a href="https://github.com/jolsfd/air-sensor">GitHub</a></p>
</div>
<script>
setInterval(function () {
// Call a function repetatively with 2 Second interval
getData();
}, 2000); //2000mSeconds update rate
function getData() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
values = this.responseText.split(" ");
document.getElementById("tempValue").innerHTML = values[0];
document.getElementById("pressureValue").innerHTML = values[1];
changeColor(values[0]);
}
};
xhttp.open("GET", "data", true);
xhttp.send();
}
function changeColor(value) {
color = "";
if (value <= 0) {
color = "#0034a8";
} else if (0 <= value && value <= 15) {
color = "#2c9aba";
} else if (16 <= value && value <= 20) {
color = "#22912d";
} else if (21 <= value && value <= 23) {
color = "#008000";
} else if (24 <= value && value <= 30) {
color = "#FFA500";
} else if (31 <= value) {
color = "#FF0000";
}
document.getElementById("title").style.backgroundColor = color;
}
</script>
</body>
</html>
"""