#include <Wire.h> // Bibliothek für I2C
#include <LiquidCrystal_I2C.h> // Bibliothek für 16x2 LCD-Display
#include <WiFi.h> // Bibliothek für WiFi
#include <HTTPClient.h> // Bibliothek für einen HTTP-Client
#include <ArduinoJson.h> // Bibliothek zum Parsen von JSON-Daten
// WiFi
const char* wifi_ssid = "Wokwi-GUEST"; // SSID
const char* wifi_password = ""; // Password
// OpenWeatherMap-API
const char* openweather_apiKey = "8c8b5cf22b1f03fc85b060f3b290f101"; // API-Key
const char* openweather_location = "BREMEN,DE"; // Ort für Wetterabfrage
// Display
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD-Objekt erstellen// WiFi
WiFiClient wifiClient;
void setup() {
// Serielle Schnittstelle initialisieren
Serial.begin(115200);
// WLAN-Verbindung aufbauen
wifiConnect();
// LCD initialisieren
lcd.init(); // LCD-Display initialisieren
lcd.backlight(); // Hintergrundbeleuchtung einschalten
}
void loop() {
// WLAN-Verbindung prüfen
if (WiFi.status() != WL_CONNECTED) {
WiFi.disconnect();
wifiConnect();
}
// Wetterdaten abrufen
String weatherData = getWeatherData();
// Wetterdaten anzeigen
displayWeatherData(weatherData);
// 5 Minuten warten
delay(300000);
}
void wifiConnect() {
WiFi.begin(wifi_ssid, wifi_password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(250);
}
Serial.println(" connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
String getWeatherData() {
String weatherData = "";
// Hier sollen die Wetterdaten vom API-Endpunkt abgefragt werden.
// Verwenden Sie dazu die Klasse "HTTPClient".
// Die Antwort (JSON-Daten) soll als String zurückgegeben werden.
return weatherData;
}
void displayWeatherData(const String& weatherData) {
// An dieser Stellen sollen die empfangenen JSON-Daten mit Hilfe
// der ArduinoJson-Library ausgewertet werden und
// Temperatur und Luftfeuchtigkeit auf dem Display dargestellt werden.
}