温湿度监测
室内温度: --
室内湿度: --
室外温度: --
室外湿度: --
舒适度: --
async function fetchData(){
try{
const res = await fetch('http://192.168.0.72:5000/latest');
const data = await res.json();
document.getElementById("inTemp").innerText = "室内温度: " + data.indoorT + "°C";
document.getElementById("inHum").innerText = "室内湿度: " + data.indoorH + "%";
document.getElementById("outTemp").innerText = "室外温度: " + data.outdoorT + "°C";
document.getElementById("outHum").innerText = "室外湿度: " + data.outdoorH + "%";
let comfort = "未知";
if(data.indoorT>=20 && data.indoorT=40 && data.indoorH<=60){
comfort = "舒适 :)";
} else if(data.indoorT<20 || data.indoorH26 || data.indoorH>60){ comfort = "热湿 :("; }
else { comfort = "一般 :/"; }
document.getElementById("comfort").innerText = "舒适度: " + comfort;
}catch(e){
console.log("Error:",e);
}
}
setInterval(fetchData,5000); // 每5秒刷新
fetchData();
Comments NOTHING