Updated
This commit is contained in:
@@ -258,6 +258,8 @@ void setup() {
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
console.log("Fetched data:", data);
|
||||
|
||||
// Update cards
|
||||
updateCard("aqiCard", data.latest.aqi, getAQIRecommendation(data.latest.aqi));
|
||||
updateCard("eco2Card", data.latest.eco2, getECO2Recommendation(data.latest.eco2));
|
||||
@@ -293,12 +295,18 @@ void setup() {
|
||||
console.error(`Value text element not found in ${cardId}`);
|
||||
}
|
||||
|
||||
if (recText && recommendation) {
|
||||
recText.textContent = recommendation.text || "";
|
||||
card.className = `card text-center ${recommendation.class || ""}`;
|
||||
// Apply color class based on recommendation
|
||||
if (recommendation && recommendation.class) {
|
||||
card.className = `card text-center ${recommendation.class}`;
|
||||
} else {
|
||||
card.className = "card text-center"; // Default class if no recommendation
|
||||
}
|
||||
|
||||
// Update recommendation text if available
|
||||
if (recText && recommendation && recommendation.text) {
|
||||
recText.textContent = recommendation.text;
|
||||
} else if (recText) {
|
||||
recText.textContent = "";
|
||||
card.className = "card text-center";
|
||||
recText.textContent = ""; // Clear text if no recommendation
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,18 +334,17 @@ void setup() {
|
||||
}
|
||||
|
||||
function getTemperatureClass(temp) {
|
||||
if (temp < 18) return { class: "moderate"};
|
||||
if (temp > 26) return { class: "poor"};
|
||||
return { class: "good"};
|
||||
if (temp < 18) return { class: "moderate", text: "" }; // Too cold
|
||||
if (temp > 26) return { class: "poor", text: "" }; // Too hot
|
||||
return { class: "good", text: "" }; // Comfortable
|
||||
}
|
||||
|
||||
function getHumidityClass(hum) {
|
||||
if (hum < 30) return { class: "moderate"};
|
||||
if (hum > 60) return { class: "poor"};
|
||||
return { class: "good"};
|
||||
if (hum < 30) return { class: "moderate", text: "" }; // Too dry
|
||||
if (hum > 60) return { class: "poor", text: "" }; // Too humid
|
||||
return { class: "good", text: "" }; // Comfortable
|
||||
}
|
||||
|
||||
// Fetch data every second
|
||||
setInterval(fetchData, 1000);
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user