From 0b8ae0ef349c7e56e5fe50d397fbf938873e19a7 Mon Sep 17 00:00:00 2001 From: sietse jonker Date: Thu, 7 Mar 2024 13:03:28 +0100 Subject: [PATCH] Refactor main.js: Add descriptions, declare variables, and update loop condition --- web/main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/main.js b/web/main.js index dad1607..ff372a0 100644 --- a/web/main.js +++ b/web/main.js @@ -1,9 +1,13 @@ +// Description: Main JavaScript file for the web application. +// arrays and stuff const sensorData = {}; -let intervalDelay = 5000; -// Create WebSocket connection. -const socket = new WebSocket("ws://145.92.8.114/ws"); let liveGraphs = []; +// variables +let intervalDelay = 5000; +let amountOfNodes = 4; + +const socket = new WebSocket("ws://145.92.8.114/ws"); function openConnection() { // Open connection socket.addEventListener("open", (event) => { @@ -192,7 +196,7 @@ function updateNodeData(node, temperature, humidity, eCO2, TVOC) { } // Call the function to create the HTML structure -for (let i = 1; i <= 4; i++) { +for (let i = 1; i <= amountOfNodes; i++) { createNodeData(i); liveGraphs.push(new liveGraph(i)); }