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