fixes dynamic node function
This commit is contained in:
10
web/main.js
10
web/main.js
@@ -29,6 +29,7 @@ function openConnection() {
|
|||||||
const jsonData = JSON.parse(event.data);
|
const jsonData = JSON.parse(event.data);
|
||||||
// Use the parsed JSON data as needed
|
// Use the parsed JSON data as needed
|
||||||
handleIncomingData(jsonData);
|
handleIncomingData(jsonData);
|
||||||
|
console.log(jsonData);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error parsing JSON:", error);
|
console.error("Error parsing JSON:", error);
|
||||||
@@ -47,8 +48,8 @@ function openConnection() {
|
|||||||
openConnection();
|
openConnection();
|
||||||
|
|
||||||
function handleIncomingData(data) {
|
function handleIncomingData(data) {
|
||||||
|
if (!data.message) {
|
||||||
nodeEventHandler(data.node);
|
nodeEventHandler(data.node);
|
||||||
|
|
||||||
nodeNumber = nodeDict[data.node];
|
nodeNumber = nodeDict[data.node];
|
||||||
temperature = data.Temp;
|
temperature = data.Temp;
|
||||||
humidity = data.Humi;
|
humidity = data.Humi;
|
||||||
@@ -56,6 +57,7 @@ function handleIncomingData(data) {
|
|||||||
TVOC = data.TVOC;
|
TVOC = data.TVOC;
|
||||||
|
|
||||||
updateNodeData(nodeNumber, temperature, humidity, CO2, TVOC);
|
updateNodeData(nodeNumber, temperature, humidity, CO2, TVOC);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function nodeEventHandler(node) {
|
function nodeEventHandler(node) {
|
||||||
@@ -71,9 +73,9 @@ function makeLiveGraph(node) {
|
|||||||
createNodeData(node);
|
createNodeData(node);
|
||||||
liveGraphs.push(new liveGraph(node));
|
liveGraphs.push(new liveGraph(node));
|
||||||
|
|
||||||
liveGraphs.forEach((graph) => {
|
console.log("Node " + node + " added to the liveGraphs array");
|
||||||
graph.makeGraph();
|
|
||||||
});
|
liveGraphs[node - 1].makeGraph();
|
||||||
}
|
}
|
||||||
|
|
||||||
//function for making the html elements for the following html code
|
//function for making the html elements for the following html code
|
||||||
|
Reference in New Issue
Block a user