added location and nodename

This commit is contained in:
2024-03-28 13:32:22 +01:00
parent c6f3c7c018
commit 1c13d20b49
2 changed files with 59 additions and 45 deletions

View File

@@ -1,17 +1,17 @@
class GaugeGroup {
constructor(nodeId, gaugesCount, maxGaugeValues, dataTypes) {
constructor(nodeId, Location, gaugesCount, maxGaugeValues, dataTypes) {
this.nodeId = nodeId;
this.gaugesCount = gaugesCount;
this.maxGaugeValues = maxGaugeValues; // Maximum value the gauge can display
this.dataTypes = dataTypes; // Array of data type names for each gauge
this.location = Location;
// Create a new div element
this.element = document.createElement("div");
this.element.className = "gaugeGroup";
// Set the HTML of the new div
this.element.innerHTML = `
<h2 class="groupTitle">Gauge Group for Node ${this.nodeId}</h2>
<h2 class="groupTitle">${this.nodeId} - ${this.location}</h2>
<div class="Node">
${Array(this.gaugesCount).fill().map((_, i) => `
<div class="Sensorvalues">

View File

@@ -46,49 +46,52 @@ function openConnection() {
openConnection();
function handleIncomingData(data) {
if (!data.node || !data.Temp || !data.Humi || !data.eCO2 || !data.TVOC) {
console.error('Invalid data received:', data);
return;
}
nodeAdressHandler(data.node, Object.keys(data).filter(key => key !== 'node'));
nodeNumber = nodeDict[data.node];
temperature = data.Temp;
humidity = data.Humi;
CO2 = data.eCO2;
TVOC = data.TVOC;
// Update the gauges with the new data
sensorData[data.node].updateGauge(1, temperature);
sensorData[data.node].updateGauge(2, humidity);
sensorData[data.node].updateGauge(3, CO2);
sensorData[data.node].updateGauge(4, TVOC);
async function handleIncomingData(data) {
if (!data.node || !data.Temp || !data.Humi || !data.eCO2 || !data.TVOC) {
console.error('Invalid data received:', data);
return;
}
await nodeAdressHandler(data.node, Object.keys(data).filter(key => key !== 'node'));
let nodeName = nodeDict[data.node];
let temperature = data.Temp;
let humidity = data.Humi;
let CO2 = data.eCO2;
let TVOC = data.TVOC;
// Update the gauges with the new data
if (sensorData[nodeName]) {
sensorData[nodeName].updateGauge(1, temperature);
sensorData[nodeName].updateGauge(2, humidity);
sensorData[nodeName].updateGauge(3, CO2);
sensorData[nodeName].updateGauge(4, TVOC);
} else {
console.error('No sensor data for node:', nodeName);
}
}
function nodeAdressHandler(node, dataTypes) {
if (!nodeArray.includes(node)) {
nodeArray.push(node);
nodeDict[node] = nodeArray.length;
// Define the maximum values for each data type
let maxGaugeValues = dataTypes.map(dataType => {
switch (dataType) {
case 'Temp': return 50;
case 'Humi': return 100;
case 'eCO2': return 3000;
case 'TVOC': return 2200;
default: return 100;
}
});
// Create a new GaugeGroup for the node
let gaugeGroup = new GaugeGroup(node, dataTypes.length, maxGaugeValues, dataTypes);
// Store the GaugeGroup in the sensorData object for later use
sensorData[node] = gaugeGroup;
}
async function nodeAdressHandler(node, dataTypes) {
let nodeInfo = await getNodeInfo(node);
let nodeName = nodeInfo.name;
let nodeLocation = nodeInfo.location;
if (!nodeArray.includes(nodeName)) {
nodeArray.push(nodeName);
nodeDict[node] = nodeName;
let maxGaugeValues = dataTypes.map(dataType => {
switch (dataType) {
case 'Temp': return 50;
case 'Humi': return 100;
case 'eCO2': return 3000;
case 'TVOC': return 2200;
default: return 100;
}
});
let gaugeGroup = new GaugeGroup(nodeName, nodeLocation, dataTypes.length, maxGaugeValues, dataTypes);
sensorData[nodeName] = gaugeGroup;
}
}
function createGauge(node, dataType) {
@@ -112,4 +115,15 @@ function updateGauge(nodeNumber, dataType, value) {
// Update the gauge here
let gauge = sensorData[nodeNumber][dataType]; // Get the gauge from the sensorData object
gauge.update(value); // Assuming the Gauge class has an update method
}
}
function getNodeInfo(node){
return fetch("http://145.92.8.114/flask?MAC=" + node)
.then(response => response.json())
.then(data => {
return {
name: data[0].Name,
location: data[0].Location // Assuming the server returns a Location property
};
});
}