-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
46 lines (41 loc) · 1.16 KB
/
index.html
File metadata and controls
46 lines (41 loc) · 1.16 KB
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
<!DOCTYPE html>
<html>
<body>
<p>
<span>LED Status: </span>
<span id="pinStatus"></span>
</p>
<button id="pollButton" onclick="togglePoll()">Poll LED status</button>
<button onclick="toggleLED()">Toggle LED Status</button>
<script>
let interval = null;
function pollLEDStatus() {
fetch("/pinStatus")
.then((res) => res.json())
.then(({ status }) => {
document.getElementById(
"pinStatus"
).innerHTML = `LED is currently ${status ? "ON" : "OFF"}`;
});
}
function startPolling() {
interval = setInterval(pollLEDStatus, 500);
}
function toggleLED() {
fetch("/toggleLED", { method: "POST" });
}
function togglePoll() {
if (interval !== null) {
clearInterval(interval);
interval = null;
document.getElementById("pollButton").innerHTML = "Poll LED status";
} else {
document.getElementById("pollButton").innerHTML =
"Stop Polling LED status";
startPolling();
}
}
pollLEDStatus();
</script>
</body>
</html>