/************************************************************************************************* PROGRAMMINFO ************************************************************************************************** Funktion: ESP32 Wetterdaten OLED-Display 1.3" ************************************************************************************************** JSON-Meldung: {"request": {"type":"City","query":"Tegernsee, Germany","language":"en","unit":"m"} ,"location": {"name":"Tegernsee","country":"Germany","region":"Bayern","lat":"47.717","lon":"11.767","timezone_id":"Europe\/Vienna","localtime":"2021-07-08 11:09","localtime_epoch":1625742540,"utc_offset":"2.0"} ,"current": {"observation_time":"09:09 AM","temperature":19,"weather_code":116,"weather_icons":["https:\/\/assets.weatherstack.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png"],"weather_descriptions":["Partly cloudy"],"wind_speed":7,"wind_degree":290,"wind_dir":"WNW","pressure":1020,"precip":0,"humidity":88,"cloudcover":75,"feelslike":19,"uv_index":3,"visibility":10,"is_day":"yes"} } ************************************************************************************************** Version: 07.07.2021 ************************************************************************************************** Board: ESP32vn IoT UNO V1.0.4 ************************************************************************************************** C++ Arduino IDE V1.8.13 ************************************************************************************************** Einstellungen: https://dl.espressif.com/dl/package_esp32_index.json http://dan.drown.org/stm32duino/package_STM32duino_index.json https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json **************************************************************************************************/ #include #include #include const char* ssid = "xxx"; const char* password = "xxx"; unsigned long lastTime = 0; // Timer set to 10 Minuten (600000) //unsigned long timerDelay = 600000; // Set timer to 10 Sekunden (10000) unsigned long timerDelay = 10000; String jsonBuffer; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); Serial.println("Verbinde"); while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Verbunden mit IP Addresse: "); Serial.println(WiFi.localIP()); Serial.println("Aktualisierung ist auf 10 Sekunden eingestellt."); } void loop() { if ((millis() - lastTime) > timerDelay) { // Check WiFi Status if(WiFi.status()== WL_CONNECTED){ String serverPath = "http://api.weatherstack.com/current?access_key=Hier deine API eintragen&query=Tegernsee"; //Hier deine API eintragen! jsonBuffer = httpGETRequest(serverPath.c_str()); Serial.println(jsonBuffer); JSONVar myObject = JSON.parse(jsonBuffer); if (JSON.typeof(myObject) == "undefined") { Serial.println("Eingabe fehlgeschlagen!"); return; } Serial.print("JSON object = "); Serial.println("Meine Wetterdaten:"); Serial.print("Ort: "); Serial.println(myObject["location"]["name"]); Serial.print("Aktuelle Temperatur: "); Serial.print(myObject["current"]["temperature"]); Serial.println("°C"); Serial.print("Luftdruck: "); Serial.print(myObject["current"]["pressure"]); Serial.println("hPa"); Serial.print("Luftfeuchte: "); Serial.print(myObject["current"]["humidity"]); Serial.println("%"); Serial.print("Bewölkung: "); Serial.print(myObject["current"]["cloudcover"]); Serial.println("%"); Serial.print("Windrichtung: "); Serial.println(myObject["current"]["wind_dir"]); } else { Serial.println("WiFi Disconnected"); } lastTime = millis(); } } String httpGETRequest(const char* serverName) { WiFiClient client; HTTPClient http; // Domain-Name http.begin(client, serverName); // HTTP POST request 200=OK int httpResponseCode = http.GET(); String payload = "{}"; if (httpResponseCode>0) { Serial.print("HTTP-Antwort Code (200=OK): "); Serial.println(httpResponseCode); Serial.println("Server-Meldung: "); payload = http.getString(); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } http.end(); return payload; }