diff --git a/ESP32_AP-Flasher/data/www/main.js b/ESP32_AP-Flasher/data/www/main.js index 2f9e8f27..7b9fe47a 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 + ' ┇ littlefs free: ' + msg.sys.littlefsfree + ' bytes'; + $('#sysinfo').innerHTML = 'free heap: ' + msg.sys.heap + ' bytes ┇ db size: ' + msg.sys.dbsize + ' bytes ┇ db record count: ' + msg.sys.recordcount + ' ┇ active filesystem free: ' + msg.sys.littlefsfree + ' bytes ' + convertSize(msg.sys.littlefsfree); if (msg.sys.apstate) { $("#apstatecolor").style.color = apstate[msg.sys.apstate].color; $("#apstate").innerHTML = apstate[msg.sys.apstate].state; @@ -127,6 +127,18 @@ function connect() { }); } +// Copied from +// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript +function convertSize(bytes){ + if (bytes >= 1073741824) { bytes = (bytes / 1073741824).toFixed(2) + " GB"; } + else if (bytes >= 1048576) { bytes = (bytes / 1048576).toFixed(2) + " MB"; } + else if (bytes >= 1024) { bytes = (bytes / 1024).toFixed(2) + " KB"; } + else if (bytes > 1) { bytes = bytes + " bytes"; } + else if (bytes == 1) { bytes = bytes + " byte"; } + else { bytes = "0 bytes"; } + return "(" + bytes + ")"; + } + function processTags(tagArray) { for (const element of tagArray) { tagmac = element.mac;