-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.js
79 lines (73 loc) · 2.2 KB
/
main.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
71
72
73
74
75
76
77
78
79
addEventListener("load", init);
function init() {
setInterval(update, 500);
update();
}
function update() {
fetchUsnul();
fetchPlasil();
fetchNightscout();
}
function fetchUsnul() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
console.log(Date.now() + " " + xhttp.readyState);
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
var data = JSON.parse(xhttp.responseText);
var element = document.getElementById("usnul");
element.innerText = data.teplota;
element.style.color = "#0000FF";
} else {
alert("Error: "+xhttp.status);
}
}
};
xhttp.open("GET","http://usnul.termo.cgcs.cz/vystup-json.php",true);
xhttp.send();
}
function fetchPlasil() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
console.log(Date.now() + " " + xhttp.readyState);
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
var data = JSON.parse(xhttp.responseText);
var element = document.getElementById("plasil");
element.innerText = data.teplota;
element.style.color = "#0000FF";
} else {
alert("Error: "+xhttp.status);
}
}
};
xhttp.open("GET","http://plasil.termo.cgcs.cz/vystup-json.php",true);
xhttp.send();
}
function fetchNightscout() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
console.log(Date.now() + " " + xhttp.readyState);
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
var data = JSON.parse(xhttp.responseText);
var element = document.getElementById("battery");
element.innerText = data.bgs[0].battery;
element.style.color = "#000000";
var element2 = document.getElementById("sgv");
var sgv = Number(data.bgs[0].sgv);
element2.innerText = sgv;
if (sgv < 4)
element2.style.color = "#FF0000";
if (sgv >= 4 && sgv < 9)
element2.style.color = "#32cd32";
if (sgv >= 9)
element2.style.color = "#FFFF00";
} else {
//alert("Error: "+xhttp.status);
}
}
};
xhttp.open("GET","http://maska.nightscout.cz/pebble",true);
xhttp.send();
}