Skip to content

Commit 3031488

Browse files
committed
Improve Reboot UX: charging awareness, progress UI, auto-reload #285
Author: kozmoz
1 parent d08f5c3 commit 3031488

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

SmartEVSE-3/data/index.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,28 @@ <h1 id="serialnr" class="h5 mb-0 text-white-800">SmartEVSE-</h1>
11731173
event.preventDefault();
11741174
}
11751175
function reboot() {
1176-
window.location.href = "/reboot";
1176+
let httpStatus;
1177+
fetch("/reboot")
1178+
.then(response => {
1179+
httpStatus = response.status;
1180+
return response.text();
1181+
})
1182+
.then(message => {
1183+
document.body.innerHTML = `<div id="rebootMsg" class="alert alert-success" role="alert"></div>`;
1184+
document.querySelector('#rebootMsg').innerText = message
1185+
if (httpStatus === 200) {
1186+
setInterval(() => document.querySelector('#rebootMsg').innerText += '.', 500);
1187+
// Keep retrying until the device responds.
1188+
setInterval(() => window.location.reload(), 5000);
1189+
} else {
1190+
document.querySelector('#rebootMsg').innerHTML
1191+
+= '<br><br><a href="#" class="alert-link" onclick="window.location.reload()">Return to webinterface</a>';
1192+
}
1193+
})
1194+
.catch(error => {
1195+
document.body.innerHTML = `<div id="errorMsg" class="alert alert-danger" role="alert"></div>`;
1196+
document.querySelector('#errorMsg').innerText = `Error: ${error}`;
1197+
});
11771198
}
11781199
function update() {
11791200
window.location.href = "/update";

SmartEVSE-3/src/network_common.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,9 +1185,13 @@ static void fn_http_server(struct mg_connection *c, int ev, void *ev_data) {
11851185
} else if (mg_http_match_uri(hm, "/reboot")) {
11861186
shouldReboot = true;
11871187
#ifndef SMARTEVSE_VERSION //sensorbox
1188-
mg_http_reply(c, 200, "", "Rebooting after 5s....");
1188+
mg_http_reply(c, 200, "", "Rebooting after 5s...");
11891189
#else
1190-
mg_http_reply(c, 200, "", "Rebooting 5s after EV stops charging....");
1190+
if (State == STATE_C) {
1191+
mg_http_reply(c, 202, "", "Reboot scheduled: Device will reboot 5 seconds after the EV stops charging...");
1192+
} else {
1193+
mg_http_reply(c, 200, "", "Device will reboot in 5 seconds...");
1194+
}
11911195
#endif
11921196
} else if (mg_http_match_uri(hm, "/settings") && !memcmp("POST", hm->method.buf, hm->method.len)) {
11931197
DynamicJsonDocument doc(64);

0 commit comments

Comments
 (0)