Advertisement
Halbheld

ESP32 E-Ink Display with WiFi and HTTP Text Retrieval

Jan 30th, 2025 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 2.24 KB | Housing | 0 0
  1. #include <WiFi.h>
  2. #include <HTTPClient.h>
  3. #include <GxEPD2_BW.h>
  4. #include <SPI.h>
  5.  
  6. // WLAN-Zugangsdaten
  7. const char* ssid = "WLANNAME";  // Dein WLAN-Name
  8. const char* password = "DeinWlanPasswort";  // Dein WLAN-Passwort
  9.  
  10. // E-Ink Display Pinbelegung
  11. #define EPD_BUSY 4
  12. #define EPD_RST 16
  13. #define EPD_DC 17
  14. #define EPD_CS 5
  15. #define EPD_CLK 18
  16. #define EPD_DIN 23
  17.  
  18. // Display initialisieren
  19. GxEPD2_BW<GxEPD2_290_GDEY029T94, GxEPD2_290_GDEY029T94::HEIGHT> display(
  20.   GxEPD2_290_GDEY029T94(EPD_CS, EPD_DC, EPD_RST, EPD_BUSY));
  21.  
  22. // URL der Webseite
  23. const char* serverName = "https://n7.eu/robots.txt";
  24.  
  25. void setup() {
  26.   // Serielle Verbindung starten
  27.   Serial.begin(115200);
  28.  
  29.   // Display initialisieren
  30.   display.init(115200);
  31.   display.setRotation(1);
  32.   display.setFullWindow();
  33.  
  34.   // Mit WLAN verbinden
  35.   Serial.println("Verbinde mit WLAN...");
  36.   WiFi.begin(ssid, password);
  37.   while (WiFi.status() != WL_CONNECTED) {
  38.     delay(500);
  39.     Serial.print(".");
  40.   }
  41.   Serial.println("Mit WLAN verbunden!");
  42.  
  43.   // Display initialisieren und erste Nachricht anzeigen
  44.   display.firstPage();
  45.   do {
  46.     display.fillScreen(GxEPD_WHITE);
  47.     display.setCursor(20, 50);
  48.     display.setTextColor(GxEPD_BLACK);
  49.     display.setTextSize(2);
  50.     display.print("WLAN verbunden!");
  51.   } while (display.nextPage());
  52. }
  53.  
  54. void loop() {
  55.   // Zeitstempel anzeigen (Aktualisierung alle 2 Minuten)
  56.   delay(120000);  // 2 Minuten warten
  57.  
  58.   // HTTP-Anfrage starten
  59.   HTTPClient http;
  60.   http.begin(serverName);  // URL der Webseite
  61.  
  62.   // HTTP GET Anfrage senden
  63.   int httpCode = http.GET();
  64.  
  65.   if (httpCode > 0) { // Wenn die Antwort erfolgreich war
  66.     String payload = http.getString();  // Antwort in String umwandeln
  67.  
  68.     Serial.println("Text empfangen:");
  69.     Serial.println(payload);  // Zum Debuggen ausgeben
  70.  
  71.     // Text auf dem Display anzeigen
  72.     display.firstPage();
  73.     do {
  74.       display.fillScreen(GxEPD_WHITE);
  75.       display.setCursor(20, 50);
  76.       display.setTextColor(GxEPD_BLACK);
  77.       display.setTextSize(2);
  78.       display.print(payload);  // Empfangenes Text anzeigen
  79.     } while (display.nextPage());
  80.   } else {
  81.     Serial.println("Fehler beim Abrufen des Textes.");
  82.   }
  83.  
  84.   // HTTP-Verbindung beenden
  85.   http.end();
  86. }
  87.  
Tags: Arduino e-ink
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement