From 5c165633d1929aed76841367553012961bb2f97e Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 3 Nov 2023 16:03:34 +0100 Subject: [PATCH] increase vTick for time screen, add lost IP event handler and system status to web interface --- data/src/css/style.scss | 1 + data/src/index.html | 14 ++++++++++++++ data/src/js/script.ts | 19 ++++++++++++++++++- src/lib/functions.cpp | 10 +++++++++- src/lib/functions.hpp | 1 + src/lib/webserver.cpp | 5 +++++ src/tasks/minute.cpp | 2 +- 7 files changed, 49 insertions(+), 3 deletions(-) diff --git a/data/src/css/style.scss b/data/src/css/style.scss index 1de809d..fe56410 100644 --- a/data/src/css/style.scss +++ b/data/src/css/style.scss @@ -20,6 +20,7 @@ $form-range-track-bg: #fff; @import "../node_modules/bootstrap/scss/navbar"; @import "../node_modules/bootstrap/scss/nav"; @import "../node_modules/bootstrap/scss/card"; +@import "../node_modules/bootstrap/scss/progress"; @import "../node_modules/bootstrap/scss/helpers"; @import "../node_modules/bootstrap/scss/utilities/api"; diff --git a/data/src/index.html b/data/src/index.html index 2d8f163..951066f 100644 --- a/data/src/index.html +++ b/data/src/index.html @@ -57,6 +57,20 @@

+
+
+
+
{{ memUsage }}%
+
+
+
Memory usage
+
{{ memFree }} / {{ memTotal }} kB
+
+
+
+
+

Uptime: {{#if uptime.h }}{{ uptime.h }}h {{/if}}{{ uptime.m }}m {{ uptime.s }}s

+
diff --git a/data/src/js/script.ts b/data/src/js/script.ts index 90846a4..e370e02 100644 --- a/data/src/js/script.ts +++ b/data/src/js/script.ts @@ -2,6 +2,23 @@ import './helpers.js'; var screens = ["Block Height", "Moscow Time", "Ticker", "Time", "Halving countdown"]; +toTime = (secs) => { + var hours = Math.floor(secs / (60 * 60)); + + var divisor_for_minutes = secs % (60 * 60); + var minutes = Math.floor(divisor_for_minutes / 60); + + var divisor_for_seconds = divisor_for_minutes % 60; + var seconds = Math.ceil(divisor_for_seconds); + + var obj = { + "h": hours, + "m": minutes, + "s": seconds + }; + return obj; +} + getBcStatus = () => { fetch('/api/status', { method: 'get' @@ -11,7 +28,7 @@ getBcStatus = () => { var source = document.getElementById("entry-template").innerHTML; var template = Handlebars.compile(source); - var context = { timerRunning: jsonData.timerRunning, currentScreen: jsonData.currentScreen, rendered: jsonData.rendered, data: jsonData.data, screens: screens, ledStatus: jsonData.ledStatus ? jsonData.ledStatus.map((t) => (t).toString(16)) : [] }; + var context = { timerRunning: jsonData.timerRunning, memUsage: Math.round(jsonData.espFreeHeap / jsonData.espHeapSize * 100), memFree: (jsonData.espFreeHeap / 1000), memTotal: (jsonData.espHeapSize / 1000), uptime: toTime(jsonData.espUptime), currentScreen: jsonData.currentScreen, rendered: jsonData.rendered, data: jsonData.data, screens: screens, ledStatus: jsonData.ledStatus ? jsonData.ledStatus.map((t) => (t).toString(16)) : [] }; document.getElementById('output').innerHTML = template(context); diff --git a/src/lib/functions.cpp b/src/lib/functions.cpp index f6a5a87..dcaf0e4 100644 --- a/src/lib/functions.cpp +++ b/src/lib/functions.cpp @@ -64,7 +64,7 @@ void setupComponents() // Serial.println(F("Leds should be on")); #ifndef NO_MCP - if (!mcp.begin_I2C()) + if (!mcp.begin_I2C(0x20)) { Serial.println(F("Error MCP23017")); pixels.setPixelColor(0, pixels.Color(255, 0, 0)); @@ -143,6 +143,8 @@ void setupWifi() } #endif + //WiFi.persistent(true); + WiFi.enableLongRange(false); setupSoftAP(); wm.setConfigPortalTimeout(preferences.getUInt("wpTimeout", 600)); @@ -156,6 +158,12 @@ void setupWifi() softAP_password.c_str()); }); bool ac = wm.autoConnect(softAP_SSID.c_str(), softAP_password.c_str()); + WiFi.onEvent(onWifiLostIp, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_LOST_IP); + +} + +void onWifiLostIp(WiFiEvent_t event, WiFiEventInfo_t info) { + ESP.restart(); } void setupPreferences() diff --git a/src/lib/functions.hpp b/src/lib/functions.hpp index 49fcb66..95177b4 100644 --- a/src/lib/functions.hpp +++ b/src/lib/functions.hpp @@ -28,6 +28,7 @@ void setCurrentScreen(uint screen); void handleScreenTasks(uint screen); void showNetworkSettings(); void toggleScreenTimer(); +void onWifiLostIp(WiFiEvent_t event, WiFiEventInfo_t info); void timebasedChangeTask(void *parameter); diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index b6093dc..a9a9d1a 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -76,6 +76,11 @@ void onApiStatus(AsyncWebServerRequest *request) root["currentScreen"] = String(getCurrentScreen()); root["timerRunning"] = timerRunning; root["numScreens"] = NUM_SCREENS; + root["espUptime"] = esp_timer_get_time() / 1000000; + root["espFreeHeap"] = ESP.getFreeHeap(); + root["espHeapSize"] = ESP.getHeapSize(); + root["espFreePsram"] = ESP.getFreePsram(); + root["espPsramSize"] = ESP.getPsramSize(); JsonArray data = root.createNestedArray("data"); JsonArray rendered = root.createNestedArray("rendered"); String epdContent[NUM_SCREENS]; diff --git a/src/tasks/minute.cpp b/src/tasks/minute.cpp index 83fe04e..e62c618 100644 --- a/src/tasks/minute.cpp +++ b/src/tasks/minute.cpp @@ -28,7 +28,7 @@ void minuteTask(void * parameter) { if(rtc.getSecond() != 0) { // Reset the event triggered flag if the second is not 0 eventTriggered = false; } - vTaskDelay(pdMS_TO_TICKS(500)); // Sleep for 500 milliseconds to avoid busy waiting + vTaskDelay(pdMS_TO_TICKS(1000)); // Sleep for 1000 milliseconds to avoid busy waiting #endif } }