mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-05 12:54:57 +00:00
update image refresh logic to be more optimized
This commit is contained in:
@@ -43,19 +43,21 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
for (const [key, value] of Object.entries(data)) {
|
for (const [key, value] of Object.entries(data)) {
|
||||||
const dataElement = document.createElement("p");
|
const dataElement = document.createElement("p");
|
||||||
dataElement.textContent = `${key}: ${value}`;
|
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
|
// Update the image
|
||||||
function updateImage() {
|
async function updateImage() {
|
||||||
var img = document.getElementById("robot-image");
|
let img = document.getElementById("robot-image");
|
||||||
img.src = "/image?" + new Date().getTime(); // Add timestamp to avoid caching
|
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
|
// Fetch and display sensor data every 1 second
|
||||||
setInterval(parseData, 1000);
|
setInterval(parseData, 1000);
|
||||||
|
|
||||||
// Update the image every 200 milliseconds
|
// Start updating the image
|
||||||
setInterval(updateImage, 100);
|
updateImage();
|
||||||
});
|
});
|
Reference in New Issue
Block a user