modified: src/esp_info.cpp
modified: src/esp_info.h modified: src/web_server.cpp
This commit is contained in:
@@ -48,7 +48,7 @@ void prettyPrintBytes(size_t bytes) {
|
|||||||
if (bytes < 1024) {
|
if (bytes < 1024) {
|
||||||
Serial.printf("%d b\n", bytes);
|
Serial.printf("%d b\n", bytes);
|
||||||
} else if (bytes < (1024 * 1024)) {
|
} else if (bytes < (1024 * 1024)) {
|
||||||
Serial.printf("%.2f kb\n", bytes / 1024.0);
|
Serial.printf("%.1f kb\n", bytes / 1024.0);
|
||||||
} else {
|
} else {
|
||||||
Serial.printf("%.2f mb\n", bytes / (1024.0 * 1024));
|
Serial.printf("%.2f mb\n", bytes / (1024.0 * 1024));
|
||||||
}
|
}
|
||||||
@@ -56,41 +56,69 @@ void prettyPrintBytes(size_t bytes) {
|
|||||||
|
|
||||||
String formatBytes(size_t bytes) {
|
String formatBytes(size_t bytes) {
|
||||||
if (bytes < 1024) return String(bytes) + " b";
|
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";
|
else return String(bytes / (1024.0 * 1024), 2) + " mb";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getCPUInfo() {
|
||||||
|
String info = "<div class='cpu-info'><h4>CPU</h4>";
|
||||||
|
info += "<p>Model: " + String(ESP.getChipModel()) + "</p>";
|
||||||
|
info += "<p>Cores: " + String(ESP.getChipCores()) + "</p>";
|
||||||
|
info += "<p>Frequency: " + String(ESP.getCpuFreqMHz()) + " MHz</p>";
|
||||||
|
info += "</div>";
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getTemperatureInfo() {
|
||||||
|
String info = "<div class='temp-info'>";
|
||||||
|
float temperature = readInternalTemperature();
|
||||||
|
if (!isnan(temperature)) {
|
||||||
|
info += "<h4>Temperature Sensor</h4>";
|
||||||
|
info += "<p>Internal Temperature: " + String(temperature, 1) + " °C</p>";
|
||||||
|
}
|
||||||
|
info += "</div>";
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getRAMInfo() {
|
||||||
|
String info = "<div class='ram-info'><h4>Internal RAM</h4>";
|
||||||
|
info += "<p>Heap Size: " + formatBytes(ESP.getHeapSize()) + "</p>";
|
||||||
|
info += "<p>Free Heap: " + formatBytes(ESP.getFreeHeap()) + "</p>";
|
||||||
|
info += "<p>Min Free Heap: " + formatBytes(ESP.getMinFreeHeap()) + "</p>";
|
||||||
|
info += "<p>Max Alloc Heap: " + formatBytes(ESP.getMaxAllocHeap()) + "</p>";
|
||||||
|
info += "</div>";
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getPSRAMInfo() {
|
||||||
|
String info = "<div class='psram-info'><h4>PSRAM</h4>";
|
||||||
|
info += "<p>PSRAM Size: " + formatBytes(ESP.getPsramSize()) + "</p>";
|
||||||
|
info += "<p>Free PSRAM: " + formatBytes(ESP.getFreePsram()) + "</p>";
|
||||||
|
info += "<p>Min Free PSRAM: " + formatBytes(ESP.getMinFreePsram()) + "</p>";
|
||||||
|
info += "<p>Max Alloc PSRAM: " + formatBytes(ESP.getMaxAllocPsram()) + "</p>";
|
||||||
|
info += "</div>";
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getFlashInfo() {
|
||||||
|
String info = "<div class='flash-info'><h4>Flash</h4>";
|
||||||
|
size_t usedBytes = ESP.getSketchSize();
|
||||||
|
size_t totalBytes = ESP.getFlashChipSize();
|
||||||
|
float usagePercent = (usedBytes * 100.0) / totalBytes;
|
||||||
|
info += "<p>Flash Size: " + formatBytes(totalBytes) + "</p>";
|
||||||
|
info += "<p>Used: " + formatBytes(usedBytes) + " (" + String(usagePercent, 1) + "%)</p>";
|
||||||
|
info += "<p>Flash Speed: " + String(ESP.getFlashChipSpeed() / 1000000) + " MHz</p>";
|
||||||
|
info += "</div>";
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
String getESPInfoHTML() {
|
String getESPInfoHTML() {
|
||||||
String html = "<div class='esp-info'><h3>ESP32 Information</h3>";
|
String html = "<div class='esp-info'><h3>ESP32 Information</h3>";
|
||||||
|
html += getTemperatureInfo();
|
||||||
html += "<h4>Internal RAM</h4>";
|
html += getCPUInfo();
|
||||||
html += "<p>Heap Size: " + formatBytes(ESP.getHeapSize()) + "</p>";
|
html += getRAMInfo();
|
||||||
html += "<p>Free Heap: " + formatBytes(ESP.getFreeHeap()) + "</p>";
|
html += getPSRAMInfo();
|
||||||
|
html += getFlashInfo();
|
||||||
html += "<h4>PSRAM</h4>";
|
|
||||||
html += "<p>PSRAM Size: " + formatBytes(ESP.getPsramSize()) + "</p>";
|
|
||||||
html += "<p>Free PSRAM: " + formatBytes(ESP.getFreePsram()) + "</p>";
|
|
||||||
|
|
||||||
html += "<h4>Flash</h4>";
|
|
||||||
size_t usedBytes = ESP.getSketchSize();
|
|
||||||
size_t totalBytes = ESP.getFlashChipSize();
|
|
||||||
float usagePercent = (usedBytes * 100.0) / totalBytes;
|
|
||||||
html += "<p>Flash Size: " + formatBytes(totalBytes) + "</p>";
|
|
||||||
html += "<p>Used: " + formatBytes(usedBytes) + " (" + String(usagePercent, 1) + "%)</p>";
|
|
||||||
html += "<p>Flash Speed: " + String(ESP.getFlashChipSpeed() / 1000000) + " MHz</p>";
|
|
||||||
|
|
||||||
html += "<h4>CPU</h4>";
|
|
||||||
html += "<p>Model: " + String(ESP.getChipModel()) + "</p>";
|
|
||||||
html += "<p>Cores: " + String(ESP.getChipCores()) + "</p>";
|
|
||||||
html += "<p>Frequency: " + String(ESP.getCpuFreqMHz()) + " MHz</p>";
|
|
||||||
|
|
||||||
float temperature = readInternalTemperature();
|
|
||||||
if (!isnan(temperature)) {
|
|
||||||
html += "<h4>Temperature Sensor</h4>";
|
|
||||||
html += "<p>Internal Temperature: " + String(temperature, 2) + " °C</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
html += "</div>";
|
html += "</div>";
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// Utility functions
|
||||||
void prettyPrintBytes(size_t bytes);
|
void prettyPrintBytes(size_t bytes);
|
||||||
void printESPInfo();
|
String formatBytes(size_t bytes);
|
||||||
String getESPInfoHTML();
|
|
||||||
float getFlashUsagePercent();
|
|
||||||
size_t getProgramFlashSize(); // Add this
|
|
||||||
size_t getAvailableFlashSize(); // Add this
|
|
||||||
String getRAMInfoHTML();
|
|
||||||
float readInternalTemperature(); // Add this to esp_info.h
|
|
||||||
|
|
||||||
|
// Individual info getters
|
||||||
|
String getCPUInfo();
|
||||||
|
String getTemperatureInfo();
|
||||||
|
String getRAMInfo();
|
||||||
|
String getPSRAMInfo();
|
||||||
|
String getFlashInfo();
|
||||||
|
|
||||||
|
// HTML generators
|
||||||
|
String getESPInfoHTML();
|
||||||
|
String getRAMInfoHTML();
|
||||||
|
|
||||||
|
// Debug print
|
||||||
|
void printESPInfo();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,6 +34,21 @@ void setupWebServer() {
|
|||||||
request->send(response);
|
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
|
// Root route with debug logging
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
Serial.print("Handling root request from IP: ");
|
Serial.print("Handling root request from IP: ");
|
||||||
|
|||||||
Reference in New Issue
Block a user