Refactor code and update websocket connection

This commit is contained in:
Sietse Jonker
2024-03-08 12:58:33 +01:00
parent 08c9bedb44
commit 3886292110
2 changed files with 43 additions and 47 deletions

View File

@@ -56,7 +56,7 @@ function handleIncomingData(data) {
function processNodeData(nodeNumber, temperature, humidity, CO2, TVOC) {
// Initialize the array for this node if it doesn't exist yet
if (!sensorData[nodeNumber]) {
if (!nodeNumber[nodeNumber]) {
sensorData[nodeNumber] = [];
}
@@ -191,14 +191,16 @@ function updateNodeData(node, temperature, humidity, eCO2, TVOC) {
document.getElementById("TVOCStatus").textContent = "Connected";
// Update the graph
liveGraphs[node - 1].updateData(temperature, humidity, eCO2, TVOC);
liveGraphs[node - 1].updateGraph();
liveGraphs[0].updateData(temperature, humidity, eCO2, TVOC);
liveGraphs[0].updateGraph();
}
createNodeData("34:85:18:B5:CF:20");
liveGraphs.push(new liveGraph("34:85:18:B5:CF:20"));
// Call the function to create the HTML structure
for (let i = 1; i <= amountOfNodes; i++) {
createNodeData(i);
liveGraphs.push(new liveGraph(i));
}
// make the graphs