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:
@@ -9,6 +9,14 @@
|
|||||||
margin: 10px;
|
margin: 10px;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
|
.error-message {
|
||||||
|
color: red;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 10px;
|
||||||
|
border: 1px solid red;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #fff0f0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -16,26 +24,42 @@
|
|||||||
<script>
|
<script>
|
||||||
function updateValues() {
|
function updateValues() {
|
||||||
console.log('Fetching ESP info...');
|
console.log('Fetching ESP info...');
|
||||||
|
document.getElementById('dashboard').innerHTML = '<div class="card">Loading...</div>';
|
||||||
|
|
||||||
fetch('/api/espinfo')
|
fetch('/api/espinfo')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
}
|
}
|
||||||
return response.text();
|
return response.json(); // Expect JSON response
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log('Data received');
|
console.log('Data received:', data);
|
||||||
document.getElementById('dashboard').innerHTML = 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 => {
|
.catch(error => {
|
||||||
console.error('Error:', 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
|
// Initial load
|
||||||
updateValues();
|
updateValues();
|
||||||
// Update every 2 seconds
|
// Update every 5 seconds (increased from 2 to reduce server load)
|
||||||
setInterval(updateValues, 2000);
|
setInterval(updateValues, 5000);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ void setupWebServer() {
|
|||||||
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
||||||
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
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
|
// 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