-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
126 lines (109 loc) · 4.18 KB
/
main.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<!--
ParksideWeb
Copyright (c) Benedikt Müssig, 2024
-->
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>ParksideWeb</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="application/javascript">
const interval = 225;
let config = {};
let data = {time: 0};
function initialize() {
console.log("Fetching configuration")
let xhr = new XMLHttpRequest();
xhr.addEventListener("error", function(e) {
console.log("Could not fetch configuration", e);
setTimeout(initialize, 500);
});
xhr.addEventListener("load", function() {
try {
console.log("Applying configuration");
config = JSON.parse(this.responseText);
document.title = "ParksideWeb v" + config["version"] + " (" + config["port"] + ")";
value.innerText = config["version"];
mode.innerText = config["port"];
} catch (e) {
console.log("Could not parse configuration", e, this.responseText);
setTimeout(initialize, 500);
return;
}
setTimeout(function() {
info.style.display = "none";
value.innerText = "";
unit.innerText = "";
bargraph.style.display = "table-row";
mode.innerText = "";
setInterval(acquire, interval);
}, 5000);
});
xhr.open("GET", new URL("/config.json", window.location.href).toString());
xhr.setRequestHeader("Accept", "application/json");
xhr.send();
}
function acquire() {
console.log("Acquiring data");
let xhr = new XMLHttpRequest();
xhr.addEventListener("error", function(e) {
console.log("Could not fetch data", e);
});
xhr.addEventListener("load", function() {
let oldTime = data["time"];
try {
data = JSON.parse(this.responseText);
} catch (e) {
console.log("Could not parse data", e, this.responseText);
setTimeout(initialize, 500);
return;
}
console.log("Data fetched and parsed", data);
if (oldTime > data["time"]) {
console.log("Skipping stale data");
return;
}
console.log("Displaying data");
mode.innerText = data["mode"];
if (data["recorded"]) {
value.innerText = data["overload"] ? "OL" : data["value"].toFixed(data["digits"]);
unit.innerText = data["unit"] + (data["polarity"].length > 0 ? "\n" + data["polarity"] : "");
needle.style.width = data["needle"] + "%";
} else {
value.innerText = "";
unit.innerText = "";
needle.style.width = "0";
}
});
xhr.open("GET", new URL("/data.json", window.location.href).toString());
xhr.setRequestHeader("Accept", "application/json");
xhr.send();
}
window.addEventListener('load', initialize);
</script>
</head>
<body>
<table id="display">
<tr id="reading">
<td>
<span id="value"></span>
<span id="unit">ParksideWeb</span>
</td>
</tr>
<tr id="bargraph">
<td><span id="needle"></span></td>
</tr>
<tr class="accent">
<td id="mode"></td>
</tr>
<tr id="info">
<td>
ParksideWeb © <a href="https://github.com/bmuessig/ParksideWeb">Benedikt Müssig</a>, 2024
</td>
</tr>
</table>
</body>
</html>