Refactor main.js: Add descriptions, declare variables, and update loop condition

This commit is contained in:
sietse jonker
2024-03-07 13:03:28 +01:00
parent bc8cc500cb
commit 0b8ae0ef34

View File

@@ -1,9 +1,13 @@
// Description: Main JavaScript file for the web application.
// arrays and stuff
const sensorData = {}; const sensorData = {};
let intervalDelay = 5000;
// Create WebSocket connection.
const socket = new WebSocket("ws://145.92.8.114/ws");
let liveGraphs = []; let liveGraphs = [];
// variables
let intervalDelay = 5000;
let amountOfNodes = 4;
const socket = new WebSocket("ws://145.92.8.114/ws");
function openConnection() { function openConnection() {
// Open connection // Open connection
socket.addEventListener("open", (event) => { socket.addEventListener("open", (event) => {
@@ -192,7 +196,7 @@ function updateNodeData(node, temperature, humidity, eCO2, TVOC) {
} }
// Call the function to create the HTML structure // Call the function to create the HTML structure
for (let i = 1; i <= 4; i++) { for (let i = 1; i <= amountOfNodes; i++) {
createNodeData(i); createNodeData(i);
liveGraphs.push(new liveGraph(i)); liveGraphs.push(new liveGraph(i));
} }