

Ziele des Projekts
Auf einem TFT E-Ink (E-Paper) mit 4,2 Zoll werden…
- links die aktuellen Wetterdaten von Open-Meteo
- rechts die Messwerte eines BME280-Sensors oder eines DHT-Sensors
… angezeigt

Der Sleep-Modus des ESP32 wird genutzt um den Prozessor während der Pausen zwischen den Anzeigezyklen in den „Schlaf“ zu versetzen. Das ⇒E-Paper-Display zeigt den Inhalt solange an bis eine Änderung erfolgt. Der ESP muss also nur nach der definierten „Schlafenszeit“ wieder aktiv werden.
Open-Meteo
Open-Meteo ist eine quelloffene Software, die unter der Lizenz ⤷CC BY 4.0 veröffentlich wird. Die Gesellschaft hat ihren Sitz in der Schweiz. Für die Nutzung ist keine Anmeldung erforderlich. Die nicht-kommerzelle Nutzung erlaubt höchstens 10.000 Aufrufe pro Tag, 5.000 pro Stunde und 600 pro Minute.
Quelle: ⤷https://open-meteo.com/en/terms
Vorbereitungen
DWD ICON API
Die Plattform Open-Meteo stellt Wetterdaten aus verschiedenen Quellen zur Verfügung, ich habe mich für den Deutschen Wetterdienst entschieden:
- aktuelle Wetterdaten:
Temperatur, Luftfeuchtigkeit, Luftdruck, Niederschlag, Windstärke, Windrichtung - 7-Tage Wettervorhersage tageweise
Temperatur minimum/maximum, „gefühlte“ Temperatur, Regenwahrscheinlichkeit, Sonnenaufgang/Sonnenuntergang
Als Erstes musst du die Zeitzone wählen und über den Button „Search“ deinen Ort suchen:
⤷https://open-meteo.com/en/docs/dwd-api

Du kannst den Aufruf der API mit den gewählten Parametern übernehmen, du musst lediglich in Zeile 96 die für deinen Ort gültigen Koordinaten innerhalb der Adresse austauschen:

Konfiguration des Mikrocontroller
Anschluss des E-Paper an den ESP32-Wroom
SPI-Pins der Mikrocontroller

Die Pins CLK, DIN (COPI) und CS sind durch den SPI-Bus des jeweiligen Mikrocontrollers festgelegt, die anderen Pins können frei vergeben werden.
| E-Paper | ESP32-Wroom |
|---|---|
| BUSY | 4 |
| RST | 15 |
| DC | 2 |
| CS | 5 |
| CLK (SCK) | 18 |
| DIN (COPI) | 23 |
| GND | GND |
| VCC | VCC |
Erläuterung zu JSON
JSON (JavaScript Object Notation) dient dem Austausch von Daten zwischen einem Server und einer Webanwendung. JSON-Daten sind eine Sammlung von Schlüssel-Wert-Paaren. Die Bibliothek ArduinoJson filtert aus den Rohdaten diese Schlüssel-Wert-Paare heraus.

Das Programm
Benötigte Bibliotheken




Bibliotheken und Variable
Die Piktogramme werden online mit ⤷https://javl.github.io/image2cpp/ in ein Array umgewandelt.


Format der Piktogramme:
- nicht größer als 60×50 Pixel
- nur schwarz weiß
- möglichst klare Konturen und deutliche Strichstärke
Der Takt des Sleep-Modus wird in Mikrosekunden erfasst-
1 Sekunde = 1.000.000 Mikrosekunden
Daher wird eine Variable vom Typ ull (= unsigned long long) definiert. Die Multiplikation dieser Variablen mit der Anzahl der Sekunden ergibt die „Schlafenszeit“.
600 Sekunden = 600.000.000 Mikrosekunden
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
#include "WiFi.h" #include "WiFiMulti.h" #include "HTTPClient.h" #include "ArduinoJson.h" #include "WiFi.h" #include "NTP3.h" #include "Adafruit_BME280.h" #include "GxEPD2_BW.h" #include "U8g2_for_Adafruit_GFX.h" // Objekt u8g2Schriften U8G2_FOR_ADAFRUIT_GFX u8g2Schriften; WiFiMulti WiFiNetzwerke; WiFiUDP wifiUdp; NTP3 ntp(wifiUdp); // Typ unsigned long long (ull) // Faktor Umrechnung zu Sekunden #define Mikro_zu_Sekunden 1000000ull // Powersafe in Sekunden #define Ruhezeit 600 Adafruit_BME280 bme; // ESP32-Wroom // Anschlüsse: CLK -> 18, DIN -> 23, CS -> 5, DC-> 2, RST -> 15, BUSY -> 4 GxEPD2_BW<GxEPD2_420_GDEY042T81, GxEPD2_420_GDEY042T81::HEIGHT> display(GxEPD2_420_GDEY042T81(/*CS*/ 5, /*DC*/ 2, /*RST*/ 15, /*BUSY*/ 4)); // ESP32-C6 // Anschlüsse: CLK -> 21, DIN -> 19, CS -> 18, DC-> 3, RST -> 10, BUSY -> 11 // GxEPD2_BW<GxEPD2_420_GDEY042T81, GxEPD2_420_GDEY042T81::HEIGHT> // display(GxEPD2_420_GDEY042T81(/*CS*/ 18, /*DC*/ 3, /*RST*/ 10, /*BUSY*/ 11)); const char* WetterDaten = "https://api.open-meteo.com/v1/forecast?latitude=50.9856&longitude=7.133&daily=temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,precipitation_probability_max,weather_code,rain_sum,showers_sum,snowfall_sum,precipitation_sum&models=dwd_icon_seamless¤t=temperature_2m,relative_humidity_2m,apparent_temperature,is_day,rain,showers,snowfall,surface_pressure,cloud_cover,precipitation,wind_speed_10m,wind_direction_10m,weather_code&timezone=Europe%2FBerlin&forecast_days=7"; // String für die vom Server gelieferten Daten String JSONDaten; // 'Sonnenuntergang', 60x30px const unsigned char Sonnenuntergang[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0xfe, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x18, 0x01, 0x80, 0x18, 0x00, 0xf8, 0x00, 0x00, 0x0c, 0x01, 0x80, 0x18, 0x00, 0x70, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x30, 0x00, 0x20, 0x00, 0x00, 0x06, 0x07, 0xe0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x04, 0x7f, 0xfe, 0x20, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x10, 0x1c, 0x00, 0x00, 0x38, 0x0c, 0x00, 0x00, 0x3c, 0x38, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x1e, 0x30, 0x00, 0x00, 0x0e, 0x78, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // 'Sonnenaufgang', 60x30px const unsigned char Sonnenaufgang[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x03, 0xfc, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x18, 0x01, 0x80, 0x18, 0x0f, 0xff, 0x00, 0x00, 0x0c, 0x01, 0x80, 0x18, 0x1f, 0xff, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x30, 0x3f, 0xff, 0xc0, 0x00, 0x06, 0x07, 0xe0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x04, 0x7f, 0xfe, 0x20, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x10, 0x1c, 0x00, 0x00, 0x38, 0x0c, 0x00, 0x00, 0x3c, 0x38, 0x00, 0x00, 0x1c, 0x1c, 0x00, 0x00, 0x1e, 0x30, 0x00, 0x00, 0x0e, 0x78, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // 'Temperatur_innen', 45x44px const unsigned char Temperatur_innen[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xfd, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x7c, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x3e, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x0f, 0xc0, 0x00, 0x00, 0x1f, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x3e, 0x02, 0x03, 0xf0, 0x00, 0x00, 0x7c, 0x04, 0x01, 0xf8, 0x00, 0x01, 0xf8, 0x04, 0x80, 0xfc, 0x00, 0x03, 0xf0, 0x04, 0x80, 0x7e, 0x00, 0x07, 0xe0, 0x04, 0x80, 0x1f, 0x00, 0x0f, 0xc0, 0x04, 0x80, 0x0f, 0x80, 0x1f, 0x80, 0x04, 0x80, 0x07, 0xe0, 0x3f, 0x00, 0x04, 0x80, 0x07, 0xe0, 0x1f, 0x00, 0x04, 0x80, 0x07, 0xe0, 0x07, 0x00, 0x04, 0x80, 0x07, 0x00, 0x07, 0x00, 0x04, 0x80, 0x07, 0x00, 0x07, 0x00, 0x04, 0x80, 0x07, 0x00, 0x07, 0x00, 0x07, 0x80, 0x07, 0x00, 0x07, 0x00, 0x07, 0x80, 0x07, 0x00, 0x07, 0x00, 0x07, 0x80, 0x07, 0x00, 0x07, 0x00, 0x07, 0x80, 0x07, 0x00, 0x07, 0x00, 0x07, 0x80, 0x07, 0x00, 0x07, 0x00, 0x07, 0x80, 0x07, 0x00, 0x07, 0x00, 0x07, 0x80, 0x07, 0x00, 0x07, 0x00, 0x0f, 0xc0, 0x07, 0x00, 0x07, 0x00, 0x1f, 0xc0, 0x07, 0x00, 0x07, 0x00, 0x1f, 0xc0, 0x07, 0x00, 0x07, 0x00, 0x1f, 0xc0, 0x07, 0x00, 0x07, 0x00, 0x1f, 0xc0, 0x07, 0x00, 0x07, 0x00, 0x0f, 0x80, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x00, 0x03, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // 'Luftfeuchtigkeit_innen', 45x44px const unsigned char Luftfeuchtigkeit_innen[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xfd, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x7c, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x3e, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x4f, 0xc0, 0x00, 0x00, 0x1f, 0x08, 0xe7, 0xe0, 0x00, 0x00, 0x3e, 0x1c, 0x43, 0xf0, 0x00, 0x00, 0x7c, 0x08, 0x01, 0xf8, 0x00, 0x01, 0xf8, 0x01, 0x08, 0xfc, 0x00, 0x03, 0xf0, 0x23, 0x9c, 0x7e, 0x00, 0x07, 0xe8, 0x71, 0x08, 0x9f, 0x00, 0x0f, 0xdc, 0x20, 0x01, 0xcf, 0x80, 0x1f, 0x88, 0x00, 0x20, 0x87, 0xe0, 0x3f, 0x00, 0x00, 0x70, 0x07, 0xe0, 0x1f, 0x00, 0x20, 0x20, 0x87, 0xe0, 0x07, 0x08, 0x70, 0x01, 0xc7, 0x00, 0x07, 0x1c, 0x20, 0x80, 0x87, 0x00, 0x07, 0x08, 0x01, 0xc0, 0x07, 0x00, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x27, 0x00, 0x07, 0x02, 0x08, 0x10, 0x77, 0x00, 0x07, 0x07, 0x1c, 0x38, 0x27, 0x00, 0x07, 0x02, 0x08, 0x10, 0x07, 0x00, 0x07, 0x40, 0x00, 0x00, 0x47, 0x00, 0x07, 0xe0, 0x40, 0x00, 0xe7, 0x00, 0x07, 0x40, 0xe0, 0x04, 0x47, 0x00, 0x07, 0x00, 0x41, 0x0e, 0x07, 0x00, 0x07, 0x00, 0x03, 0x84, 0x07, 0x00, 0x07, 0x08, 0x01, 0x00, 0x07, 0x00, 0x07, 0x1c, 0x00, 0x00, 0x27, 0x00, 0x07, 0x08, 0x84, 0x08, 0x77, 0x00, 0x07, 0x01, 0xce, 0x1c, 0x27, 0x00, 0x07, 0x00, 0x84, 0x08, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0x00, 0x03, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // 'Temperatur_aussen', 50x39px const unsigned char Temperatur_aussen [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x78, 0x00, 0x7e, 0x00, 0x00, 0x06, 0x00, 0x1c, 0x00, 0x7e, 0x00, 0x03, 0xfc, 0x00, 0x06, 0x00, 0x42, 0x00, 0x07, 0x00, 0x00, 0x03, 0x00, 0x42, 0x00, 0x0c, 0x00, 0x00, 0x03, 0x80, 0x42, 0x00, 0x18, 0x00, 0x00, 0x01, 0x80, 0x42, 0x00, 0x30, 0x00, 0x00, 0x01, 0x80, 0x42, 0x00, 0x20, 0x00, 0x00, 0x01, 0x80, 0x42, 0x00, 0x60, 0x00, 0x00, 0x00, 0xc0, 0x43, 0xc0, 0x60, 0x00, 0x00, 0x00, 0x70, 0x42, 0x00, 0x60, 0x00, 0x00, 0x00, 0x10, 0x42, 0x00, 0x60, 0x00, 0x00, 0x00, 0x10, 0x42, 0x00, 0x60, 0x00, 0x00, 0x00, 0x10, 0x42, 0x00, 0x60, 0x00, 0x00, 0x00, 0x30, 0x43, 0xc0, 0x30, 0x00, 0x00, 0x00, 0x70, 0x42, 0x00, 0x18, 0x00, 0x00, 0x00, 0xe0, 0x42, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xc0, 0x42, 0x00, 0x03, 0x00, 0x00, 0x00, 0xc0, 0x5a, 0x00, 0x01, 0x80, 0x00, 0x00, 0x80, 0x5b, 0xc0, 0x01, 0x80, 0x00, 0x03, 0x80, 0x5a, 0x00, 0x00, 0xc0, 0x00, 0x06, 0x00, 0x5a, 0x00, 0x00, 0x70, 0x00, 0x0c, 0x00, 0x5a, 0x00, 0x00, 0x7f, 0xff, 0xf8, 0x00, 0x5a, 0x00, 0x00, 0x1f, 0xff, 0xc0, 0x00, 0x5b, 0xc0, 0x00, 0x00, 0x81, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0xdb, 0x00, 0x00, 0x00, 0x81, 0x00, 0x01, 0xdb, 0x80, 0x00, 0x00, 0x81, 0x00, 0x03, 0xdb, 0xc0, 0x00, 0x00, 0x81, 0x00, 0x07, 0xbd, 0xc0, 0x00, 0x00, 0x81, 0x00, 0x07, 0x7e, 0xc0, 0x00, 0x00, 0x81, 0x00, 0x06, 0x7e, 0x40, 0x00, 0x01, 0x81, 0x00, 0x06, 0x7e, 0x40, 0x00, 0x01, 0x81, 0x00, 0x07, 0x7e, 0xc0, 0x00, 0x01, 0x01, 0x80, 0x07, 0xbd, 0xc0, 0x00, 0x01, 0x01, 0x80, 0x03, 0xc3, 0xc0, 0x00, 0x03, 0xff, 0x80, 0x01, 0xe7, 0x80, 0x00, 0x03, 0xff, 0x80, 0x00, 0xff, 0x00 }; // 'Regen', 40x47px const unsigned char Regen[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x60, 0x02, 0x80, 0x02, 0x00, 0xa0, 0x04, 0x80, 0x22, 0x00, 0x90, 0x04, 0x40, 0x34, 0x01, 0x10, 0x00, 0x40, 0x00, 0x01, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, 0x04, 0x01, 0xff, 0xc1, 0x10, 0x03, 0x87, 0x00, 0x70, 0xe0, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x00, 0x70, 0x00, 0x07, 0x00, 0x00, 0xe0, 0x00, 0x01, 0x00, 0x01, 0x80, 0x00, 0x01, 0x80, 0x03, 0x00, 0x00, 0x00, 0xe0, 0x06, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x00, 0x02, 0x60, 0x00, 0x00, 0x00, 0x03, 0x60, 0xc1, 0xc1, 0xc1, 0x83, 0x3f, 0xe3, 0xf3, 0x77, 0xe6, 0x0e, 0x3e, 0x1e, 0x1c, 0x3c, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00 }; // 'Barometer', 45x46px const unsigned char Barometer[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x07, 0xf0, 0x3f, 0x80, 0x00, 0x00, 0x1f, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x3c, 0x00, 0x00, 0xf0, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x3c, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x1e, 0x00, 0x03, 0xc6, 0x00, 0x00, 0x07, 0x00, 0x03, 0x87, 0x80, 0x00, 0x03, 0x80, 0x07, 0x07, 0xe0, 0x00, 0x01, 0x80, 0x0e, 0x07, 0xf8, 0x00, 0x01, 0xc0, 0x1c, 0x07, 0xfe, 0x00, 0x00, 0xe0, 0x18, 0x07, 0xfc, 0x00, 0x00, 0x60, 0x18, 0x07, 0xf8, 0x00, 0x00, 0x70, 0x30, 0x07, 0xf0, 0x00, 0x00, 0x30, 0x30, 0x07, 0xf0, 0x00, 0x00, 0x30, 0x30, 0x07, 0xf0, 0x00, 0x00, 0x18, 0x60, 0x07, 0x38, 0x00, 0x00, 0x18, 0x60, 0x04, 0x3c, 0x00, 0x00, 0x18, 0x60, 0x00, 0x1e, 0x00, 0x00, 0x18, 0x60, 0x00, 0x0f, 0x80, 0x00, 0x08, 0x40, 0x00, 0x0f, 0xc0, 0x00, 0x08, 0x40, 0x00, 0x0f, 0xc0, 0x00, 0x08, 0x40, 0x00, 0x0f, 0xc0, 0x00, 0x08, 0x40, 0x00, 0x0f, 0xc0, 0x00, 0x08, 0x60, 0x00, 0x07, 0xe0, 0x00, 0x18, 0x60, 0x00, 0x00, 0xd0, 0x00, 0x18, 0x60, 0x00, 0x00, 0x70, 0x00, 0x18, 0x70, 0x00, 0x00, 0x78, 0x00, 0x18, 0x30, 0x00, 0x00, 0x7c, 0x00, 0x30, 0x30, 0x00, 0x00, 0x60, 0x00, 0x30, 0x38, 0x00, 0x00, 0x20, 0x00, 0x70, 0x18, 0x00, 0x00, 0x00, 0x00, 0x60, 0x1c, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0e, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x06, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, 0x07, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x1e, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x7c, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x1f, 0x00, 0x03, 0xe0, 0x00, 0x00, 0x0f, 0xe0, 0x1f, 0xc0, 0x00, 0x00, 0x01, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // 'Luftfeuchtigkeit_aussen', 45x39px const unsigned char Luftfeuchtigkeit_aussen[] PROGMEM = { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x40, 0x20, 0x07, 0xff, 0xe0, 0x40, 0xe0, 0x70, 0x0e, 0x00, 0xf8, 0xe0, 0x40, 0x20, 0x7c, 0x00, 0x3c, 0x40, 0x00, 0x0f, 0xf8, 0x00, 0x0e, 0x00, 0x20, 0x1e, 0x00, 0x00, 0x07, 0x00, 0x70, 0x38, 0x00, 0x00, 0x07, 0x08, 0x20, 0x70, 0x00, 0x00, 0x03, 0x1c, 0x00, 0xe0, 0x00, 0x00, 0x03, 0x88, 0x00, 0xc0, 0x00, 0x00, 0x03, 0x80, 0x00, 0xc0, 0x00, 0x00, 0x01, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x30, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x30, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x30, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x70, 0x00, 0x60, 0x00, 0x00, 0x00, 0xe0, 0x20, 0x30, 0x00, 0x00, 0x01, 0xc8, 0x70, 0x1c, 0x00, 0x00, 0x01, 0x9c, 0x20, 0x46, 0x00, 0x00, 0x01, 0x88, 0x00, 0xe7, 0x00, 0x00, 0x01, 0x00, 0x00, 0x43, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x80, 0x00, 0x0e, 0x00, 0x40, 0x11, 0xe0, 0x00, 0x18, 0x08, 0xe0, 0x38, 0x7f, 0xff, 0xf0, 0x1c, 0x40, 0x10, 0x3f, 0xff, 0xc0, 0x08, 0x00, 0x00, 0x83, 0x02, 0x00, 0x00, 0x40, 0x01, 0xc1, 0x02, 0x02, 0x00, 0xe0, 0x10, 0x85, 0x02, 0x07, 0x00, 0x40, 0x38, 0x0f, 0x02, 0x02, 0x04, 0x00, 0x10, 0x05, 0x02, 0x00, 0x0e, 0x00, 0x00, 0x01, 0x02, 0x00, 0x04, 0x00, 0x00, 0x83, 0x02, 0x00, 0x40, 0x20, 0x01, 0xc3, 0x02, 0x00, 0xe0, 0x70, 0x40, 0x87, 0x02, 0x00, 0x40, 0x20, 0xe0, 0x06, 0x03, 0x00, 0x02, 0x00, 0x40, 0x86, 0x03, 0x80, 0x07, 0x00, 0x01, 0xcf, 0xff, 0x80, 0x02, 0x00, 0x00, 0x8f, 0xff, 0x00, 0x00, 0x00 }; |
Der setup-Teil
- die verfügbaren WiFi-Netze werden als Werte-Paar definiert:
SSID des Routers/Repeaters, PasswortWiFiNetzwerke.addAP("Router_SSID", "xxxxxxxx");
WiFiNetzwerke.addAP("Repeater_1", "xxxxxxxx"); - das Programm versucht eine WiFi-Verbindung mit dem WiFi-Netz mit der größten Signalstärke (RSSI) aufzubauen
- Zeitzone bestimmen
ntp.ruleDST("CEST", Last, Sun, Mar, 2, 120);CEST: Central European Summertime
Beginn europäische Sommerzeit letzter Sonntag im März 2 Uhr UTC + 2 Stunden
CET: Central European Time
Beginn Normalzeit letzter Sonntag im Oktober 3 Uhr UTC + 1 Stundentp.ruleSTD("CET", Last, Sun, Oct, 3, 60); - ntp starten
Zeitserver deutscher NTP-Poolntp.begin("de.pool.ntp.org") - jeder Anweisung für die Anzeige muss
u8g2Schriftenvorangestellt werden:u8g2Schriften.setFont(u8g2_font_helvB14_tf);
u8g2Schriften.setForegroundColor(GxEPD_WHITE);
u8g2Schriften.setBackgroundColor(GxEPD_BLACK);
u8g2Schriften.setCursor(1, 20);
u8g2Schriften.print("...");
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
void setup() { // Schriften von u8g2 display zuordnen u8g2Schriften.begin(display); bme.begin(0x76); // Bildschirm starten display.init(115200, true, 2, false); display.setRotation(0); // vollständigen Bildschirm nutzen display.setFullWindow(); display.fillScreen(GxEPD_WHITE); // Stations-Modus WiFi.mode(WIFI_STA); WiFi.setSleep(false); WiFi.setAutoReconnect(true); // verfügbare WiFi-Netzwerke WiFiNetzwerke.addAP("Router_SSID", "xxxxxxxx"); WiFiNetzwerke.addAP("Repeater_1", "xxxxxxx"); WiFiNetzwerke.addAP("Repeater_2", "xxxxxxxx"); WiFiVerbinden(); /* Zeitzone CEST: Central European Summertime Beginn europäische Sommerzeit letzter Sonntag im März 2 Uhr UTC + 2 Stunden */ ntp.ruleDST("CEST", Last, Sun, Mar, 2, 120); // CET: Central European Time // Beginn Normalzeit letzter Sonntag im Oktober 3 Uhr UTC + 1 Stunde ntp.ruleSTD("CET", Last, Sun, Oct, 3, 60); // ntp starten Zeitserver deutscher NTP-Pool ntp.begin("de.pool.ntp.org"); ntp.updateInterval(10000); } |
Der loop-Teil
Der loop-Teil zeichnet Piktogramme und Linien und schreibt den Text (innen/außen).
Die Darstellung von Grafik und Text wird mit einer do … while Schleife erledigt.
|
1 2 3 4 5 6 7 8 |
do { u8g2Schriften.setCursor(100, 15); u8g2Schriften.print("außen"); u8g2Schriften.setCursor(300, 15); u8g2Schriften.print("innen"); } while (display.nextPage()); |
Am Ende des loop-Teils wird der Sleep-Timer mit der festgelegten Anzahl von Sekunden gestartet.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
void loop() { display.fillScreen(GxEPD_WHITE); // Piktogramme display.drawBitmap(210, 162, Sonnenaufgang, 60, 30, GxEPD_BLACK); display.drawBitmap(210, 218, Sonnenuntergang, 60, 30, GxEPD_BLACK); display.drawBitmap(214, 30, Temperatur_innen, 45, 44, GxEPD_BLACK); display.drawBitmap(214, 90, Luftfeuchtigkeit_innen, 45, 44, GxEPD_BLACK); display.drawBitmap(1, 35, Temperatur_aussen, 50, 39, GxEPD_BLACK); display.drawBitmap(1, 100, Luftfeuchtigkeit_aussen, 45, 39, GxEPD_BLACK); display.drawBitmap(1, 155, Barometer, 45, 46, GxEPD_BLACK); display.drawBitmap(1, 210, Regen, 40, 47, GxEPD_BLACK); u8g2Schriften.setFont(u8g2_font_helvB14_tf); u8g2Schriften.setBackgroundColor(GxEPD_WHITE); u8g2Schriften.setForegroundColor(GxEPD_BLACK); do { u8g2Schriften.setCursor(100, 15); u8g2Schriften.print("außen"); u8g2Schriften.setCursor(300, 15); u8g2Schriften.print("innen"); } while (display.nextPage()); display.drawFastHLine(1, 20, display.width(), GxEPD_BLACK); display.drawFastVLine(200, 1, display.height(), GxEPD_BLACK); display.drawFastHLine(1, 280, display.width(), GxEPD_BLACK); display.drawFastHLine(200, 150, display.width(), GxEPD_BLACK); u8g2Schriften.setFont(u8g2_font_helvB24_tf); DatenAnzeigen(); // Sleep-Modus esp_sleep_enable_timer_wakeup(Ruhezeit * Mikro_zu_Sekunden); esp_deep_sleep_start(); } |
Die Funktion DatenAnzeigen()
- zunächst wird mit der Funktion WiFiVerbinden() der Status der WiFi-Verbindung geprüft:
|
1 2 3 4 5 6 7 8 9 10 11 |
void WiFiVerbinden() { if (WiFi.status() != WL_CONNECTED) { WiFi.disconnect(); if (WiFiNetzwerke.run() == WL_CONNECTED) { delay(200); } } } |
- steht der Open-Meteo Server temporär nicht zur Verfügung, werden maximal 6 Versuche unternommen die Verbindung herzustellen
bei einem erfolgreichen Abruf der Daten (httpCode > 0) wird die Variable Verbindung auf true gesetzt und die Schleife verlassen
|
1 2 3 4 5 6 7 |
while(!Verbindung) { httpCode = http.GET(); if(httpCode > 0) Verbindung = true; AnzahlVersuche ++; if(AnzahlVersuche > 5) break; } |
- die Anweisung deserializeJson wandelt die Daten um, die Daten können anschließend ausgewertet werden
- einige Daten liegen im Format float vor
sie werden gespeichert, auf eine Nachkommastelle gekürzt und mit replace wird der . durch ein , ersetztfloat aktuelleTemperatur = JSONDaten["current"]["temperature_2m"];
String AnzeigeTemperatur = String(aktuelleTemperatur, 1);
AnzeigeTemperatur.replace(".", ",");float Regen = JSONDaten["current"]["rain"];
String AnzeigeRegen = String(Regen, 1);
AnzeigeRegen.replace(".", ","); - nach der Umwandlung in einen String und in einen ganzzahligen Wert mit int wird der Luftdruck angezeigt
u8g2Schriften.print(String(int(JSONDaten["current"]["surface_pressure"])) + " hPa"); - die Regenwahrscheinlichkeit wird als int dargestellt
u8g2Schriften.print(String(JSONDaten["daily"]["precipitation_probability_max"][0]) + "%"); - die Daten für Sonnenaufgang und Sonnenuntergang liegen als String vor
String Sonnenaufgang = JSONDaten["daily"]["sunrise"][0];
String Sonnenuntergang = JSONDaten["daily"]["sunset"][0];
die letzten Zeichen der Strings Sonnenaufgang/Sonnenuntergang enthalten die Uhrzeit der MessungSonnenuntergang = Sonnenuntergang.substring(11, Sonnenuntergang.length());
Sonnenaufgang = Sonnenaufgang.substring(11, Sonnenaufgang.length()); - die Temperatur des BME280 wird ermittelt, auf eine Nachkommastelle und mit replace wird der . durch ein , ersetzt
String TemperaturBME = String(bme.readTemperature(), 1);TemperaturBME.replace(".", ",");
der Wert für die Luftfeuchtigkeit wird als ganze Zahl dargestellt
String LuftfeuchtigkeitBME = String(bme.readHumidity(), 0);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
void DatenAnzeigen() { int AnzahlVersuche = 0; int httpCode; HTTPClient http; bool Verbindung = false; // Verbindung zu Open-Meteo aufbauen WiFiVerbinden(); ntp.update(); http.begin(WetterDaten); while (!Verbindung) { httpCode = http.GET(); if (httpCode > 0) Verbindung = true; // Server antwortet nach 6 Versuchen nicht AnzahlVersuche++; if (AnzahlVersuche > 5) break; } // erfolgreiche Verbindung if (Verbindung) { // Daten als String holen und "entpacken" String ServerAntwort = http.getString(); JsonDocument JSONDaten; deserializeJson(JSONDaten, ServerAntwort); // Messwerte Open-Meteo erfassen float aktuelleTemperatur = JSONDaten["current"]["temperature_2m"]; float Regen = JSONDaten["current"]["rain"]; String Sonnenaufgang = JSONDaten["daily"]["sunrise"][0]; String Sonnenuntergang = JSONDaten["daily"]["sunset"][0]; // auf 1 Nachkommastelle kürzen String AnzeigeRegen = String(Regen, 1); String AnzeigeTemperatur = String(aktuelleTemperatur, 1); // . durch , ersetzen AnzeigeTemperatur.replace(".", ","); AnzeigeRegen.replace(".", ","); // Uhrzeit aus Sonnenauf-/untergang extrahieren Sonnenuntergang = Sonnenuntergang.substring(11, Sonnenuntergang.length()); Sonnenaufgang = Sonnenaufgang.substring(11, Sonnenaufgang.length()); // Daten BME280 erfassen String TemperaturBME = String(bme.readTemperature(), 1); String LuftfeuchtigkeitBME = String(bme.readHumidity(), 0); String LuftdruckBME = String(bme.readPressure() / 100.0); // float verwendet den . als Dezimaltrennzeichen // . mit replace durch , ersetzen TemperaturBME.replace(".", ","); LuftdruckBME.replace(".", ","); LuftfeuchtigkeitBME.replace(".", ","); // Daten anzeigen do { u8g2Schriften.setFont(u8g2_font_helvB24_tf); // Temperatur u8g2Schriften.setCursor(55, 70); u8g2Schriften.print(AnzeigeTemperatur + " °C"); u8g2Schriften.setCursor(280, 70); u8g2Schriften.print(TemperaturBME + " °C"); // Luftfeuchtigkeit u8g2Schriften.setCursor(55, 130); u8g2Schriften.print(String(JSONDaten["current"]["relative_humidity_2m"]) + "%"); u8g2Schriften.setCursor(280, 130); u8g2Schriften.print(LuftfeuchtigkeitBME + " %"); // Luftdruck u8g2Schriften.setCursor(55, 190); u8g2Schriften.print(String(int(JSONDaten["current"]["surface_pressure"])) + " hPa"); // Regenwahrscheinlichkeit u8g2Schriften.setCursor(55, 250); u8g2Schriften.print(String(JSONDaten["daily"]["precipitation_probability_max"][0]) + "%"); // Sonnenauf-/untergang u8g2Schriften.setCursor(210, 190); u8g2Schriften.setCursor(280, 190); u8g2Schriften.print(Sonnenaufgang); u8g2Schriften.setCursor(210, 250); u8g2Schriften.setCursor(280, 250); u8g2Schriften.print(Sonnenuntergang); // Zeit Daten Server/lokal u8g2Schriften.setFont(u8g2_font_helvB14_tf); u8g2Schriften.setCursor(10, 300); u8g2Schriften.print(String(JSONDaten["current"]["time"]).substring(11, String(JSONDaten["current"]["time"]).length())) + " Uhr"; u8g2Schriften.setCursor(210, 300); if (ntp.update()) { u8g2Schriften.print(String(ntp.formattedTime("%H:%M"))); } } while (display.nextPage()); } } |
Quellen
- Espressif WiFi-API
- Espressif Sleep Modes Dokumentation
- ESP32 Deep Sleep – detalierte Beschreibung
- Open-Meteo Lizenz
- DWD-API bei Open-Meteo
Letzte Aktualisierung: