From 7b51330675af46e26945e2b91b367c346348a9f0 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Wed, 15 Jan 2025 16:32:23 +0100 Subject: [PATCH] update image refresh logic to be more optimized --- src/Python/flask/web/static/script.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Python/flask/web/static/script.js b/src/Python/flask/web/static/script.js index 39d7c4f..95bc757 100644 --- a/src/Python/flask/web/static/script.js +++ b/src/Python/flask/web/static/script.js @@ -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(); }); \ No newline at end of file