modified: server.js

modified:   static/js/sensor-1.js
This commit is contained in:
IrisVega 2024-07-20 17:38:37 +08:00
parent 3ae436f20f
commit d305f0e03c
2 changed files with 11 additions and 7 deletions

View File

@ -60,14 +60,18 @@ function getLatestSensorData(callback) {
callback({ error: 'Error fetching latest sensor data' });
return;
}
const data = results[0];
const timestamps = data.map(row => new Date(row.timestamp).toISOString().slice(0, 19).replace('T', ' '));
const temperatures = data.map(row => row.temperature);
const humidities = data.map(row => row.humidity);
const co2 = data.map(row => row.co2);
const pressure = data.map(row => row.pressure);
callback({
temperature: data.temperature,
humidity: data.humidity,
co2: data.co2,
pressure: data.pressure,
timestamps: data.timestamp.map(row => new Date(row.timestamp).toISOString().slice(0, 19).replace('T', ' '))
timestamps,
temperatures,
humidities,
co2,
pressure
});
});
}

View File

@ -27,7 +27,7 @@ document.addEventListener('DOMContentLoaded', function () {
// 添加新的数据
timestamps.push(data.timestamps);
temperatures.push(data.temperature);
temperatures.push(data.temperatures);
updateChart();
});