Skip to content

Commit 29dee4c

Browse files
committed
Remove test code, display when connection lost
1 parent 7aa46d3 commit 29dee4c

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

web/src/index.htm

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,68 @@
99
<body>
1010
<div class="heading">STORINATOR</div>
1111

12-
<button
13-
id="powerLed"
14-
type="button"
15-
class="button"
16-
disabled>
17-
POWER LED
12+
<button id="powerLed" type="button" class="button" disabled>
13+
NO CONNECTION
1814
</button>
1915
<button
2016
id="powerBtn"
2117
type="button"
2218
class="activeButton"
23-
onclick="sendCommand(CMD_POWER_ON)">
19+
onclick="sendCommand(CMD_POWER_ON)"
20+
>
2421
POWER ON
2522
</button>
2623
<button
2724
id="standByBtn"
2825
type="button"
2926
class="activeButton"
30-
onclick="sendCommand(CMD_STAND_BY)">
27+
onclick="sendCommand(CMD_STAND_BY)"
28+
>
3129
STANDBY
3230
</button>
3331
<button
3432
id="resetBtn"
3533
type="button"
3634
class="activeButton"
37-
onclick="sendCommand(CMD_RESET)">
35+
onclick="sendCommand(CMD_RESET)"
36+
>
3837
RESET
3938
</button>
4039
<button
4140
id="killBtn"
4241
type="button"
4342
class="activeButton"
44-
onclick="sendCommand(CMD_KILL)">
43+
onclick="sendCommand(CMD_KILL)"
44+
>
4545
KILL
46-
</button>
46+
</button>
4747

48-
<a href="https://github.com/MatiasG19/arduino-remote-switch">Arduino Remote Switch on GitHub</a>
48+
<a href="https://github.com/MatiasG19/arduino-remote-switch"
49+
>Arduino Remote Switch on GitHub</a
50+
>
4951

5052
<script>
51-
const CMD_POWER_ON = "powerOn", CMD_STAND_BY = "standBy", CMD_RESET = "reset", CMD_KILL = "kill"
52-
const REQ_POWER_STATUS = "powerStatus"
53+
const CMD_POWER_ON = 'powerOn',
54+
CMD_STAND_BY = 'standBy',
55+
CMD_RESET = 'reset',
56+
CMD_KILL = 'kill'
57+
const REQ_POWER_STATUS = 'powerStatus'
5358

54-
setInterval(() => {
55-
togglePowerLedColor(true)
59+
setInterval(() => {
5660
requestStatus(REQ_POWER_STATUS)
5761
}, 3000)
5862

5963
function togglePowerLedColor(state) {
6064
const powerLed = document.getElementById('powerLed')
61-
if (state) {
62-
powerLed.style.color = "#27e670"
65+
if (state == 'on') {
66+
powerLed.textContent = 'POWER LED'
67+
powerLed.style.color = '#27e670'
68+
} else if (state == 'off') {
69+
powerLed.textContent = 'POWER LED'
70+
powerLed.style.color = '#eb1e8f'
6371
} else {
64-
powerLed.style.color = "#eb1e8f"
72+
powerLed.style.color = '#cfcfcf'
73+
powerLed.textContent = 'NO CONNECTION'
6574
}
6675
}
6776

@@ -84,12 +93,17 @@
8493
xhttp.onreadystatechange = function () {
8594
if (this.readyState == 4 && this.status == 200) {
8695
console.debug(`requestStatus:${request}:${this.responseText}`)
87-
if(request == REQ_POWER_STATUS && typeof this.response === "string") {
88-
if(this.response.toString().includes(REQ_POWER_STATUS+":on"))
89-
togglePowerLedColor(true)
90-
else
91-
togglePowerLedColor(false)
96+
if (
97+
request == REQ_POWER_STATUS &&
98+
typeof this.response === 'string'
99+
) {
100+
if (this.response.toString().includes(REQ_POWER_STATUS + ':on'))
101+
togglePowerLedColor('on')
102+
else togglePowerLedColor('off')
92103
}
104+
} else if (this.readyState == 4 && this.status == 404) {
105+
togglePowerLedColor('nocon')
106+
console.log('No connection to server.')
93107
}
94108
}
95109
xhttp.open('GET', request, true)

0 commit comments

Comments
 (0)