fixes dynamic node function

This commit is contained in:
sietse jonker
2024-03-14 15:21:51 +01:00
parent 4fd8c3d958
commit b3d80c1194

View File

@@ -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