v2.8.0: Weather icon in header
Adds a small weather icon in the header, right where the old camera button used to be. Shows current conditions (sun, cloud, sun-behind-cloud, rain, snow, thunderstorm) for whichever location is currently active, including active location presets, so switching to e.g. Milan shows Milan's weather. Powered by the free Open-Meteo API (no API key needed), refreshed automatically every 10 minutes in the background, or immediately after switching to a different location preset. Icons are drawn entirely with TFT_eSPI basic shapes (circles, lines), no image files or extra fonts needed. The initial implementation failed to parse Open-Meteo's response (ArduinoJson "InvalidInput") because the API replies with Transfer-Encoding: chunked and streaming directly from http.getStream() didn't reassemble the chunks correctly. Fixed by collecting the full body via http.getString() first, then parsing that. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
33
src/weather.h
Normal file
33
src/weather.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// Sehr einfache Wetteranzeige (Icon im Header, dort wo frueher der
|
||||
// Cam-Button war) - fragt periodisch die aktuelle Wetterlage fuer den
|
||||
// gerade aktiven Standort ab (also inkl. aktivem Standort-Preset, siehe
|
||||
// LocationManager::getHomeLocation() - wenn dort z.B. Mailand ausgewaehlt
|
||||
// ist, zeigt das Icon das Wetter in Mailand). Nutzt die kostenlose
|
||||
// Open-Meteo-API (kein API-Key noetig).
|
||||
namespace Weather {
|
||||
enum class Condition {
|
||||
Unknown, // noch keine erfolgreiche Abfrage - Icon zeigt nichts an
|
||||
Clear,
|
||||
PartlyCloudy,
|
||||
Cloudy,
|
||||
Rain,
|
||||
Snow,
|
||||
Thunderstorm
|
||||
};
|
||||
|
||||
// Muss regelmaessig aus dem NetTask (Core 0) aufgerufen werden - kuemmert
|
||||
// sich intern um das Abfrage-Intervall (Config::WEATHER_FETCH_INTERVAL_MS)
|
||||
// und erkennt eine Standort-Aenderung (z.B. anderes aktives Preset), um
|
||||
// dann sofort neu abzufragen statt bis zum naechsten reguleren Intervall
|
||||
// zu warten.
|
||||
void update();
|
||||
|
||||
// Aktuell bekannte Wetterlage, threadsicher genug fuer diesen Zweck (ein
|
||||
// einzelnes uint8-artiges Enum, das nur vom NetTask geschrieben und vom
|
||||
// UI-Thread gelesen wird - kein Lock noetig, ein kurzfristig veraltetes
|
||||
// Lesen ist unkritisch).
|
||||
Condition current();
|
||||
}
|
||||
Reference in New Issue
Block a user