diff --git a/data_embed/index.html b/data_embed/index.html index 9c462df..6c170a2 100644 --- a/data_embed/index.html +++ b/data_embed/index.html @@ -34,14 +34,13 @@ Restore - +
+ +
@@ -1361,6 +1360,15 @@
+
+ +
diff --git a/data_embed/script.js b/data_embed/script.js index 999bee4..4009c2d 100644 --- a/data_embed/script.js +++ b/data_embed/script.js @@ -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.
This action will be ignored if you have APRSIS and LoRa TX disabled!"); +}); + +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(); \ No newline at end of file diff --git a/data_embed/style.css b/data_embed/style.css index e69de29..8499c23 100644 --- a/data_embed/style.css +++ b/data_embed/style.css @@ -0,0 +1,8 @@ +.alert-fixed { + position:fixed; + top: 0px; + left: 0px; + width: 100%; + z-index:9999; + border-radius:0px +} \ No newline at end of file diff --git a/src/utils.cpp b/src/utils.cpp index 7aecffc..b04384b 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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; } diff --git a/src/web_utils.cpp b/src/web_utils.cpp index 4b3fae6..d5125c7 100644 --- a/src/web_utils.cpp +++ b/src/web_utils.cpp @@ -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);