From fd22bc0378f6516bdbce0c6a6d2f260221d62227 Mon Sep 17 00:00:00 2001 From: Mimoja Date: Tue, 4 Jul 2023 19:03:23 +0200 Subject: [PATCH] Fix: Properly calculate db size for SystemInfo So far the calculated size for the tagDB in the frontend was purely based on the size of each of its static entries. However the data pointer as well as the json based config string can occupy additional memory which is not accounted for. We are therefore introducing a helper function to properly calculate the DBs size. Signed-off-by: Mimoja --- ESP32_AP-Flasher/data/www/main.js | 2 +- ESP32_AP-Flasher/src/web.cpp | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ESP32_AP-Flasher/data/www/main.js b/ESP32_AP-Flasher/data/www/main.js index c68c7ecf..75588c28 100644 --- a/ESP32_AP-Flasher/data/www/main.js +++ b/ESP32_AP-Flasher/data/www/main.js @@ -94,7 +94,7 @@ function connect() { processTags(msg.tags); } if (msg.sys) { - $('#sysinfo').innerHTML = 'free heap: ' + msg.sys.heap + ' bytes ┇ db size: ' + msg.sys.dbsize + ' bytes ┇ db record count: ' + msg.sys.recordcount + ' ┇ filesystem free: ' + convertSize(msg.sys.littlefsfree); + $('#sysinfo').innerHTML = 'free heap: ' + msg.sys.heap + ' bytes ┇ db size: ' + convertSize(msg.sys.dbsize) + " ("+ msg.sys.dbsize + ' bytes) ┇ db record count: ' + msg.sys.recordcount + ' ┇ filesystem free: ' + convertSize(msg.sys.littlefsfree); if (msg.sys.apstate) { $("#apstatecolor").style.color = apstate[msg.sys.apstate].color; $("#apstate").innerHTML = apstate[msg.sys.apstate].state; diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index 5c0336fb..a192f404 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -127,15 +127,25 @@ void wsErr(String text) { if (wsMutex) xSemaphoreGive(wsMutex); } +size_t dbSize(){ + size_t size = tagDB.size() * sizeof(tagRecord); + for(auto &tag : tagDB) { + if (tag->data) + size += tag->len; + size += tag->modeConfigJson.length(); + } + return size; +} + void wsSendSysteminfo() { - DynamicJsonDocument doc(150); + DynamicJsonDocument doc(250); JsonObject sys = doc.createNestedObject("sys"); time_t now; time(&now); sys["currtime"] = now; sys["heap"] = ESP.getFreeHeap(); sys["recordcount"] = tagDB.size(); - sys["dbsize"] = tagDB.size() * sizeof(tagRecord); + sys["dbsize"] = dbSize(); sys["littlefsfree"] = Storage.freeSpace(); sys["apstate"] = apInfo.state; sys["runstate"] = config.runStatus;