From b3d80c1194a82c8d3c708cf0e7fc018364f392f1 Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Thu, 14 Mar 2024 15:21:51 +0100 Subject: [PATCH] fixes dynamic node function --- web/main.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/main.js b/web/main.js index 235c834..8ca88dc 100644 --- a/web/main.js +++ b/web/main.js @@ -29,6 +29,7 @@ function openConnection() { const jsonData = JSON.parse(event.data); // Use the parsed JSON data as needed handleIncomingData(jsonData); + console.log(jsonData); } catch (error) { console.error("Error parsing JSON:", error); @@ -47,8 +48,8 @@ function openConnection() { openConnection(); function handleIncomingData(data) { + if (!data.message) { nodeEventHandler(data.node); - nodeNumber = nodeDict[data.node]; temperature = data.Temp; humidity = data.Humi; @@ -56,6 +57,7 @@ function handleIncomingData(data) { TVOC = data.TVOC; updateNodeData(nodeNumber, temperature, humidity, CO2, TVOC); + } } function nodeEventHandler(node) { @@ -71,9 +73,9 @@ function makeLiveGraph(node) { createNodeData(node); liveGraphs.push(new liveGraph(node)); - liveGraphs.forEach((graph) => { - graph.makeGraph(); - }); + console.log("Node " + node + " added to the liveGraphs array"); + + liveGraphs[node - 1].makeGraph(); } //function for making the html elements for the following html code