Compare commits

...

3 Commits

Author SHA1 Message Date
872a3d7269 modified: src/esp_info.cpp
modified:   src/esp_info.h
	modified:   src/web_server.cpp
2025-04-12 22:10:43 +02:00
bec84c512d Changes:
modified:   src/main.cpp        Added 30 seconds timeout for connection attempts

	modified:   src/esp_info.cpp    Refactored functions and decimals
	modified:   src/esp_info.h      Refactored functions and decimals

	modified:   src/web_server.cpp  Add WiFi status endpoint
2025-04-12 22:06:28 +02:00
0f5b098130 Files changed:
modified:   data/www/dashboard.html
	modified:   src/web_server.cpp

dashboard.html working, but ram and psram are duplicated
2025-04-12 21:37:50 +02:00
5 changed files with 129 additions and 44 deletions

View File

@@ -9,6 +9,14 @@
margin: 10px;
border-radius: 10px;
}
.error-message {
color: red;
padding: 20px;
margin: 10px;
border: 1px solid red;
border-radius: 10px;
background: #fff0f0;
}
</style>
</head>
<body>
@@ -16,26 +24,42 @@
<script>
function updateValues() {
console.log('Fetching ESP info...');
document.getElementById('dashboard').innerHTML = '<div class="card">Loading...</div>';
fetch('/api/espinfo')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
return response.json(); // Expect JSON response
})
.then(data => {
console.log('Data received');
document.getElementById('dashboard').innerHTML = data;
console.log('Data received:', data);
if (!data) throw new Error('Empty response');
let html = '';
Object.entries(data).forEach(([key, value]) => {
html += `
<div class="card">
<h3>${key}</h3>
<p>${value}</p>
</div>`;
});
document.getElementById('dashboard').innerHTML = html;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('dashboard').innerHTML = 'Error loading data';
document.getElementById('dashboard').innerHTML =
`<div class="error-message">
Error loading data: ${error.message}<br>
Please check if the ESP32 is connected and the server is running.
</div>`;
});
}
// Initial load
updateValues();
// Update every 2 seconds
setInterval(updateValues, 2000);
// Update every 5 seconds (increased from 2 to reduce server load)
setInterval(updateValues, 5000);
</script>
</body>
</html>

View File

@@ -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 = "<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 html = "<div class='esp-info'><h3>ESP32 Information</h3>";
html += "<h4>Internal RAM</h4>";
html += "<p>Heap Size: " + formatBytes(ESP.getHeapSize()) + "</p>";
html += "<p>Free Heap: " + formatBytes(ESP.getFreeHeap()) + "</p>";
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 += getTemperatureInfo();
html += getCPUInfo();
html += getRAMInfo();
html += getPSRAMInfo();
html += getFlashInfo();
html += "</div>";
return html;
}

View File

@@ -5,14 +5,22 @@
#pragma once
#include <Arduino.h>
// 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

View File

@@ -25,6 +25,9 @@ bool setupWiFi() {
// Set config portal timeout (optional)
wm.setConfigPortalTimeout(180); // 3 minutes
// Set connection timeout to avoid "connectTimeout not set" warnings
wm.setConnectTimeout(30); // 30 seconds timeout for connection attempts
// Set custom hostname (optional)
wm.setHostname("Audio2MIDI");

View File

@@ -27,6 +27,28 @@ void setupWebServer() {
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
// ESP Info endpoint
server.on("/api/espinfo", HTTP_GET, [](AsyncWebServerRequest *request) {
String htmlContent = getESPInfoHTML() + getRAMInfoHTML();
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", htmlContent);
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: ");