Files changed:

modified:   data/www/dashboard.html
	modified:   src/web_server.cpp

dashboard.html working, but ram and psram are duplicated
This commit is contained in:
2025-04-12 21:37:50 +02:00
parent 6d55c2315a
commit 0f5b098130
2 changed files with 37 additions and 6 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

@@ -27,6 +27,13 @@ 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);
});
// Root route with debug logging
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
Serial.print("Handling root request from IP: ");