mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
added sensordata to website
This commit is contained in:
@@ -34,7 +34,7 @@ def move():
|
||||
|
||||
@app.route('/data', methods=['GET'])
|
||||
def data():
|
||||
return jsonify({"kobuki_message": kobuki_message})
|
||||
return kobuki_message
|
||||
|
||||
|
||||
|
||||
|
@@ -6,7 +6,6 @@ document.querySelectorAll(".btn").forEach(button => {
|
||||
// Haal de waarde van de knop op
|
||||
const direction = event.target.value;
|
||||
|
||||
// Verstuur de richting naar de server met fetch
|
||||
fetch("/move", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -22,4 +21,28 @@ document.querySelectorAll(".btn").forEach(button => {
|
||||
console.error("Error:", error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Fetch data from the server
|
||||
async function fetchData() {
|
||||
const response = await fetch("/data");
|
||||
const data = await response.json();
|
||||
return data;
|
||||
}
|
||||
|
||||
// Parse the data and show it on the website
|
||||
async function parseData() {
|
||||
const data = await fetchData();
|
||||
console.log("Fetched data:", data); // Log the fetched data
|
||||
const sensorDataContainer = document.getElementById("sensor-data");
|
||||
sensorDataContainer.innerHTML = ""; // Clear previous data
|
||||
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
const dataElement = document.createElement("p");
|
||||
dataElement.textContent = `${key}: ${value}`;
|
||||
sensorDataContainer.appendChild(dataElement);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and display sensor data every 5 seconds
|
||||
setInterval(parseData, 5000);
|
||||
});
|
@@ -28,6 +28,8 @@
|
||||
</div>
|
||||
<div class="container">
|
||||
<h1>Sensor Data</h1>
|
||||
<div id="sensor-data">
|
||||
</div>
|
||||
</div>
|
||||
<script src="../static/script.js"></script>
|
||||
</body>
|
||||
|
Reference in New Issue
Block a user