update image refresh logic to be more optimized

This commit is contained in:
2025-01-15 16:32:23 +01:00
parent 3bb44ad4ab
commit 7b51330675

View File

@@ -43,19 +43,21 @@ document.addEventListener("DOMContentLoaded", function() {
for (const [key, value] of Object.entries(data)) {
const dataElement = document.createElement("p");
dataElement.textContent = `${key}: ${value}`;
sensorDataContainer.appendChild(dataElement); // Voeg het element toe aan de container
sensorDataContainer.appendChild(dataElement); // Add the element to the container
}
}
// Update the image
function updateImage() {
var img = document.getElementById("robot-image");
async function updateImage() {
let img = document.getElementById("robot-image");
img.src = "/image?" + new Date().getTime(); // Add timestamp to avoid caching
// Wait for 200 milliseconds before fetching the next image
setTimeout(updateImage, 200);
}
// Fetch and display sensor data every 1 second
setInterval(parseData, 1000);
// Update the image every 200 milliseconds
setInterval(updateImage, 100);
// Start updating the image
updateImage();
});