made indentification by mac adres instead of name
This commit is contained in:
@@ -54,18 +54,18 @@ async function handleIncomingData(data) {
|
||||
|
||||
await nodeAdressHandler(data.node, Object.keys(data).filter(key => key !== 'node'));
|
||||
|
||||
let nodeName = nodeDict[data.node];
|
||||
let nodeName = nodeDict[data.node].name;
|
||||
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);
|
||||
if (sensorData[data.node]) {
|
||||
sensorData[data.node].updateGauge(1, temperature);
|
||||
sensorData[data.node].updateGauge(2, humidity);
|
||||
sensorData[data.node].updateGauge(3, CO2);
|
||||
sensorData[data.node].updateGauge(4, TVOC);
|
||||
} else {
|
||||
console.error('No sensor data for node:', nodeName);
|
||||
}
|
||||
@@ -73,11 +73,18 @@ async function handleIncomingData(data) {
|
||||
|
||||
async function nodeAdressHandler(node, dataTypes) {
|
||||
let nodeInfo = await getNodeInfo(node);
|
||||
|
||||
if (!nodeInfo) {
|
||||
console.error('No node info found for node:', node);
|
||||
return;
|
||||
}
|
||||
|
||||
let nodeName = nodeInfo.name;
|
||||
let nodeLocation = nodeInfo.location;
|
||||
if (!nodeArray.includes(nodeName)) {
|
||||
nodeArray.push(nodeName);
|
||||
nodeDict[node] = nodeName;
|
||||
|
||||
if (!nodeArray.includes(node)) {
|
||||
nodeArray.push(node);
|
||||
nodeDict[node] = {name: nodeName, location: nodeLocation};
|
||||
|
||||
let maxGaugeValues = dataTypes.map(dataType => {
|
||||
switch (dataType) {
|
||||
@@ -90,7 +97,7 @@ async function nodeAdressHandler(node, dataTypes) {
|
||||
});
|
||||
|
||||
let gaugeGroup = new GaugeGroup(nodeName, nodeLocation, dataTypes.length, maxGaugeValues, dataTypes);
|
||||
sensorData[nodeName] = gaugeGroup;
|
||||
sensorData[node] = gaugeGroup;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,11 +126,20 @@ function updateGauge(nodeNumber, dataType, value) {
|
||||
|
||||
function getNodeInfo(node){
|
||||
return fetch("http://145.92.8.114/getNodeInfo?macAdress=" + node)
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.length == 0) {
|
||||
throw new Error('No data returned for node: ' + node);
|
||||
}
|
||||
return {
|
||||
name: data[0].Name,
|
||||
location: data[0].Location // Assuming the server returns a Location property
|
||||
};
|
||||
});
|
||||
})
|
||||
|
||||
}
|
Reference in New Issue
Block a user