diff --git a/src/esp_info.cpp b/src/esp_info.cpp index 03f6464..268e67c 100644 --- a/src/esp_info.cpp +++ b/src/esp_info.cpp @@ -48,7 +48,7 @@ void prettyPrintBytes(size_t bytes) { if (bytes < 1024) { Serial.printf("%d b\n", bytes); } else if (bytes < (1024 * 1024)) { - Serial.printf("%.2f kb\n", bytes / 1024.0); + Serial.printf("%.1f kb\n", bytes / 1024.0); } else { Serial.printf("%.2f mb\n", bytes / (1024.0 * 1024)); } @@ -56,41 +56,69 @@ void prettyPrintBytes(size_t bytes) { String formatBytes(size_t bytes) { if (bytes < 1024) return String(bytes) + " b"; - else if (bytes < (1024 * 1024)) return String(bytes / 1024.0, 2) + " kb"; + else if (bytes < (1024 * 1024)) return String(bytes / 1024.0, 1) + " kb"; else return String(bytes / (1024.0 * 1024), 2) + " mb"; } +String getCPUInfo() { + String info = "

CPU

"; + info += "

Model: " + String(ESP.getChipModel()) + "

"; + info += "

Cores: " + String(ESP.getChipCores()) + "

"; + info += "

Frequency: " + String(ESP.getCpuFreqMHz()) + " MHz

"; + info += "
"; + return info; +} + +String getTemperatureInfo() { + String info = "
"; + float temperature = readInternalTemperature(); + if (!isnan(temperature)) { + info += "

Temperature Sensor

"; + info += "

Internal Temperature: " + String(temperature, 1) + " °C

"; + } + info += "
"; + return info; +} + +String getRAMInfo() { + String info = "

Internal RAM

"; + info += "

Heap Size: " + formatBytes(ESP.getHeapSize()) + "

"; + info += "

Free Heap: " + formatBytes(ESP.getFreeHeap()) + "

"; + info += "

Min Free Heap: " + formatBytes(ESP.getMinFreeHeap()) + "

"; + info += "

Max Alloc Heap: " + formatBytes(ESP.getMaxAllocHeap()) + "

"; + info += "
"; + return info; +} + +String getPSRAMInfo() { + String info = "

PSRAM

"; + info += "

PSRAM Size: " + formatBytes(ESP.getPsramSize()) + "

"; + info += "

Free PSRAM: " + formatBytes(ESP.getFreePsram()) + "

"; + info += "

Min Free PSRAM: " + formatBytes(ESP.getMinFreePsram()) + "

"; + info += "

Max Alloc PSRAM: " + formatBytes(ESP.getMaxAllocPsram()) + "

"; + info += "
"; + return info; +} + +String getFlashInfo() { + String info = "

Flash

"; + size_t usedBytes = ESP.getSketchSize(); + size_t totalBytes = ESP.getFlashChipSize(); + float usagePercent = (usedBytes * 100.0) / totalBytes; + info += "

Flash Size: " + formatBytes(totalBytes) + "

"; + info += "

Used: " + formatBytes(usedBytes) + " (" + String(usagePercent, 1) + "%)

"; + info += "

Flash Speed: " + String(ESP.getFlashChipSpeed() / 1000000) + " MHz

"; + info += "
"; + return info; +} + String getESPInfoHTML() { String html = "

ESP32 Information

"; - - html += "

Internal RAM

"; - html += "

Heap Size: " + formatBytes(ESP.getHeapSize()) + "

"; - html += "

Free Heap: " + formatBytes(ESP.getFreeHeap()) + "

"; - - html += "

PSRAM

"; - html += "

PSRAM Size: " + formatBytes(ESP.getPsramSize()) + "

"; - html += "

Free PSRAM: " + formatBytes(ESP.getFreePsram()) + "

"; - - html += "

Flash

"; - size_t usedBytes = ESP.getSketchSize(); - size_t totalBytes = ESP.getFlashChipSize(); - float usagePercent = (usedBytes * 100.0) / totalBytes; - html += "

Flash Size: " + formatBytes(totalBytes) + "

"; - html += "

Used: " + formatBytes(usedBytes) + " (" + String(usagePercent, 1) + "%)

"; - html += "

Flash Speed: " + String(ESP.getFlashChipSpeed() / 1000000) + " MHz

"; - - html += "

CPU

"; - html += "

Model: " + String(ESP.getChipModel()) + "

"; - html += "

Cores: " + String(ESP.getChipCores()) + "

"; - html += "

Frequency: " + String(ESP.getCpuFreqMHz()) + " MHz

"; - - float temperature = readInternalTemperature(); - if (!isnan(temperature)) { - html += "

Temperature Sensor

"; - html += "

Internal Temperature: " + String(temperature, 2) + " °C

"; -} - - + html += getTemperatureInfo(); + html += getCPUInfo(); + html += getRAMInfo(); + html += getPSRAMInfo(); + html += getFlashInfo(); html += "
"; return html; } diff --git a/src/esp_info.h b/src/esp_info.h index 9e0495f..3d41fc0 100644 --- a/src/esp_info.h +++ b/src/esp_info.h @@ -5,14 +5,22 @@ #pragma once #include +// Utility functions void prettyPrintBytes(size_t bytes); -void printESPInfo(); -String getESPInfoHTML(); -float getFlashUsagePercent(); -size_t getProgramFlashSize(); // Add this -size_t getAvailableFlashSize(); // Add this -String getRAMInfoHTML(); -float readInternalTemperature(); // Add this to esp_info.h +String formatBytes(size_t bytes); +// Individual info getters +String getCPUInfo(); +String getTemperatureInfo(); +String getRAMInfo(); +String getPSRAMInfo(); +String getFlashInfo(); + +// HTML generators +String getESPInfoHTML(); +String getRAMInfoHTML(); + +// Debug print +void printESPInfo(); #endif diff --git a/src/web_server.cpp b/src/web_server.cpp index aa3c3d4..8a33246 100644 --- a/src/web_server.cpp +++ b/src/web_server.cpp @@ -34,6 +34,21 @@ void setupWebServer() { request->send(response); }); + // Add WiFi status endpoint + server.on("/api/wifi/status", HTTP_GET, [](AsyncWebServerRequest *request) { + String json; + if (WiFi.status() == WL_CONNECTED) { + json = "{\"connected\":true,\"ssid\":\"" + WiFi.SSID() + + "\",\"ip\":\"" + WiFi.localIP().toString() + + "\",\"rssi\":" + String(WiFi.RSSI()) + "}"; + } else { + json = "{\"connected\":false}"; + } + AsyncWebServerResponse *response = request->beginResponse(200, "application/json", json); + response->addHeader("Access-Control-Allow-Origin", "*"); + request->send(response); + }); + // Root route with debug logging server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { Serial.print("Handling root request from IP: ");