added location and nodename
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
class GaugeGroup {
|
class GaugeGroup {
|
||||||
constructor(nodeId, gaugesCount, maxGaugeValues, dataTypes) {
|
constructor(nodeId, Location, gaugesCount, maxGaugeValues, dataTypes) {
|
||||||
this.nodeId = nodeId;
|
this.nodeId = nodeId;
|
||||||
this.gaugesCount = gaugesCount;
|
this.gaugesCount = gaugesCount;
|
||||||
this.maxGaugeValues = maxGaugeValues; // Maximum value the gauge can display
|
this.maxGaugeValues = maxGaugeValues; // Maximum value the gauge can display
|
||||||
this.dataTypes = dataTypes; // Array of data type names for each gauge
|
this.dataTypes = dataTypes; // Array of data type names for each gauge
|
||||||
|
this.location = Location;
|
||||||
// Create a new div element
|
// Create a new div element
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "gaugeGroup";
|
this.element.className = "gaugeGroup";
|
||||||
|
|
||||||
// Set the HTML of the new div
|
// Set the HTML of the new div
|
||||||
this.element.innerHTML = `
|
this.element.innerHTML = `
|
||||||
<h2 class="groupTitle">Gauge Group for Node ${this.nodeId}</h2>
|
<h2 class="groupTitle">${this.nodeId} - ${this.location}</h2>
|
||||||
<div class="Node">
|
<div class="Node">
|
||||||
${Array(this.gaugesCount).fill().map((_, i) => `
|
${Array(this.gaugesCount).fill().map((_, i) => `
|
||||||
<div class="Sensorvalues">
|
<div class="Sensorvalues">
|
||||||
|
@@ -46,33 +46,39 @@ function openConnection() {
|
|||||||
|
|
||||||
openConnection();
|
openConnection();
|
||||||
|
|
||||||
function handleIncomingData(data) {
|
async function handleIncomingData(data) {
|
||||||
if (!data.node || !data.Temp || !data.Humi || !data.eCO2 || !data.TVOC) {
|
if (!data.node || !data.Temp || !data.Humi || !data.eCO2 || !data.TVOC) {
|
||||||
console.error('Invalid data received:', data);
|
console.error('Invalid data received:', data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeAdressHandler(data.node, Object.keys(data).filter(key => key !== 'node'));
|
await nodeAdressHandler(data.node, Object.keys(data).filter(key => key !== 'node'));
|
||||||
|
|
||||||
nodeNumber = nodeDict[data.node];
|
let nodeName = nodeDict[data.node];
|
||||||
temperature = data.Temp;
|
let temperature = data.Temp;
|
||||||
humidity = data.Humi;
|
let humidity = data.Humi;
|
||||||
CO2 = data.eCO2;
|
let CO2 = data.eCO2;
|
||||||
TVOC = data.TVOC;
|
let TVOC = data.TVOC;
|
||||||
|
|
||||||
// Update the gauges with the new data
|
// Update the gauges with the new data
|
||||||
sensorData[data.node].updateGauge(1, temperature);
|
if (sensorData[nodeName]) {
|
||||||
sensorData[data.node].updateGauge(2, humidity);
|
sensorData[nodeName].updateGauge(1, temperature);
|
||||||
sensorData[data.node].updateGauge(3, CO2);
|
sensorData[nodeName].updateGauge(2, humidity);
|
||||||
sensorData[data.node].updateGauge(4, TVOC);
|
sensorData[nodeName].updateGauge(3, CO2);
|
||||||
|
sensorData[nodeName].updateGauge(4, TVOC);
|
||||||
|
} else {
|
||||||
|
console.error('No sensor data for node:', nodeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function nodeAdressHandler(node, dataTypes) {
|
async function nodeAdressHandler(node, dataTypes) {
|
||||||
if (!nodeArray.includes(node)) {
|
let nodeInfo = await getNodeInfo(node);
|
||||||
nodeArray.push(node);
|
let nodeName = nodeInfo.name;
|
||||||
nodeDict[node] = nodeArray.length;
|
let nodeLocation = nodeInfo.location;
|
||||||
|
if (!nodeArray.includes(nodeName)) {
|
||||||
|
nodeArray.push(nodeName);
|
||||||
|
nodeDict[node] = nodeName;
|
||||||
|
|
||||||
// Define the maximum values for each data type
|
|
||||||
let maxGaugeValues = dataTypes.map(dataType => {
|
let maxGaugeValues = dataTypes.map(dataType => {
|
||||||
switch (dataType) {
|
switch (dataType) {
|
||||||
case 'Temp': return 50;
|
case 'Temp': return 50;
|
||||||
@@ -83,11 +89,8 @@ function nodeAdressHandler(node, dataTypes) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a new GaugeGroup for the node
|
let gaugeGroup = new GaugeGroup(nodeName, nodeLocation, dataTypes.length, maxGaugeValues, dataTypes);
|
||||||
let gaugeGroup = new GaugeGroup(node, dataTypes.length, maxGaugeValues, dataTypes);
|
sensorData[nodeName] = gaugeGroup;
|
||||||
|
|
||||||
// Store the GaugeGroup in the sensorData object for later use
|
|
||||||
sensorData[node] = gaugeGroup;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,3 +116,14 @@ function updateGauge(nodeNumber, dataType, value) {
|
|||||||
let gauge = sensorData[nodeNumber][dataType]; // Get the gauge from the sensorData object
|
let gauge = sensorData[nodeNumber][dataType]; // Get the gauge from the sensorData object
|
||||||
gauge.update(value); // Assuming the Gauge class has an update method
|
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
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user