mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 12:24:57 +00:00
added sensordata to website
This commit is contained in:
@@ -34,7 +34,7 @@ def move():
|
|||||||
|
|
||||||
@app.route('/data', methods=['GET'])
|
@app.route('/data', methods=['GET'])
|
||||||
def data():
|
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
|
// Haal de waarde van de knop op
|
||||||
const direction = event.target.value;
|
const direction = event.target.value;
|
||||||
|
|
||||||
// Verstuur de richting naar de server met fetch
|
|
||||||
fetch("/move", {
|
fetch("/move", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -22,4 +21,28 @@ document.querySelectorAll(".btn").forEach(button => {
|
|||||||
console.error("Error:", error);
|
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>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Sensor Data</h1>
|
<h1>Sensor Data</h1>
|
||||||
|
<div id="sensor-data">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="../static/script.js"></script>
|
<script src="../static/script.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user