feat: send beacon and reboot buttons
This commit is contained in:
parent
67e1c528f3
commit
5337cb2d46
|
|
@ -34,14 +34,13 @@
|
|||
<a class="dropdown-item" href="#" id="restore">Restore</a>
|
||||
</div>
|
||||
</li>
|
||||
<!-- <li class="nav-item dropdown">
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Device</a>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="#" id="reboot">Reboot</a>
|
||||
<a class="dropdown-item" href="#" id="shutdown">Shutdown</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<!-- <li class="nav-item">
|
||||
<a class="nav-link" href="#" id="received-packets">
|
||||
Received packets
|
||||
</a>
|
||||
|
|
@ -839,7 +838,7 @@
|
|||
</div>
|
||||
<div class="col-lg-9 col-sm-12">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="col-6">
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
|
|
@ -854,9 +853,9 @@
|
|||
>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="col-6 d-grid gap-2">
|
||||
<button class="btn btn-primary">Send beacon now</button>
|
||||
</div> -->
|
||||
<div class="col-6 d-grid gap-2">
|
||||
<button class="btn btn-primary" id="send-beacon">Send beacon now</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
<div class="col-12">
|
||||
|
|
@ -1361,6 +1360,15 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
|
||||
<div id="toast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="toast-header">
|
||||
<strong class="me-auto">System Message</strong>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="toast-body text-center"></div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="/bootstrap.js"></script>
|
||||
<script src="/script.js"></script>
|
||||
|
|
|
|||
|
|
@ -216,6 +216,30 @@ function loadSettings(settings) {
|
|||
toggleFields();
|
||||
}
|
||||
|
||||
function showToast(message) {
|
||||
const el = document.querySelector('#toast');
|
||||
|
||||
el.querySelector('.toast-body').innerHTML = message;
|
||||
|
||||
(new bootstrap.Toast(el)).show();
|
||||
}
|
||||
|
||||
document.getElementById('send-beacon').addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
fetch("/action?type=send-beacon", { method: "POST" });
|
||||
|
||||
showToast("Your beacon will be sent in a moment. <br> <u>This action will be ignored if you have APRSIS and LoRa TX disabled!</u>");
|
||||
});
|
||||
|
||||
document.getElementById('reboot').addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
fetch("/action?type=reboot", { method: "POST" });
|
||||
|
||||
showToast("Your device will be rebooted in a while");
|
||||
});
|
||||
|
||||
const bmeCheckbox = document.querySelector("input[name='bme.active']");
|
||||
|
||||
const stationModeSelect = document.querySelector("select[name='stationMode']");
|
||||
|
|
@ -443,4 +467,4 @@ form.addEventListener("submit", async (event) => {
|
|||
setTimeout(checkConnection, 2000);
|
||||
});
|
||||
|
||||
fetchSettings();
|
||||
fetchSettings();
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
.alert-fixed {
|
||||
position:fixed;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
width: 100%;
|
||||
z-index:9999;
|
||||
border-radius:0px
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ namespace Utils {
|
|||
uint32_t lastTx = millis() - lastBeaconTx;
|
||||
String beaconPacket, secondaryBeaconPacket;
|
||||
|
||||
if (lastTx >= Config.beacon.interval*60*1000) {
|
||||
if (lastBeaconTx == 0 || lastTx >= Config.beacon.interval*60*1000) {
|
||||
beaconUpdate = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "web_utils.h"
|
||||
|
||||
extern Configuration Config;
|
||||
extern uint32_t lastBeaconTx;
|
||||
|
||||
extern const char web_index_html[] asm("_binary_data_embed_index_html_gz_start");
|
||||
extern const char web_index_html_end[] asm("_binary_data_embed_index_html_gz_end");
|
||||
|
|
@ -163,6 +164,21 @@ namespace WEB_Utils {
|
|||
ESP.restart();
|
||||
}
|
||||
|
||||
void handleAction(AsyncWebServerRequest *request) {
|
||||
String type = request->getParam("type", false)->value();
|
||||
|
||||
if (type == "send-beacon") {
|
||||
Serial.println(lastBeaconTx);
|
||||
lastBeaconTx = 0;
|
||||
|
||||
request->send(200, "text/plain", "Beacon will be sent in a while");
|
||||
} else if (type == "reboot") {
|
||||
ESP.restart();
|
||||
} else {
|
||||
request->send(404, "text/plain", "Not Found");
|
||||
}
|
||||
}
|
||||
|
||||
void handleStyle(AsyncWebServerRequest *request) {
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/css", (const uint8_t*)web_style_css, web_style_css_len);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
|
|
@ -194,6 +210,7 @@ namespace WEB_Utils {
|
|||
server.on("/status", HTTP_GET, handleStatus);
|
||||
server.on("/configuration.json", HTTP_GET, handleReadConfiguration);
|
||||
server.on("/configuration.json", HTTP_POST, handleWriteConfiguration);
|
||||
server.on("/action", HTTP_POST, handleAction);
|
||||
server.on("/style.css", HTTP_GET, handleStyle);
|
||||
server.on("/script.js", HTTP_GET, handleScript);
|
||||
server.on("/bootstrap.css", HTTP_GET, handleBootstrapStyle);
|
||||
|
|
|
|||
Loading…
Reference in New Issue