From c6f95e9cfd78c0dba4c3d27a3576f01ae9a2f18a Mon Sep 17 00:00:00 2001 From: jonas Date: Thu, 2 Jan 2020 16:17:29 +0100 Subject: [PATCH] Added Wifi Routine on unsuccessful connect --- E-Paper_Showerthoughts.ino | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/E-Paper_Showerthoughts.ino b/E-Paper_Showerthoughts.ino index 9f9bf3b..b5edcd8 100644 --- a/E-Paper_Showerthoughts.ino +++ b/E-Paper_Showerthoughts.ino @@ -52,11 +52,24 @@ void loop() { void connectToWifi() { WiFi.begin(ssid, password); + int connectTries = 0; // Counter for unsuccessful connects to WiFi Serial.print("WIFI: Connecting "); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); + + if(connectTries % 4 == 3) { + WiFi.begin(ssid, password); + } + + if(connectTries >= 20) { + Serial.println("Unable to connect to " + WiFi.SSID() + ". ESP32 going to deep sleep."); + esp_wifi_stop(); + esp_bt_controller_disable(); + esp_deep_sleep_start(); + } + connectTries++; } Serial.println("WIFI: Connected to network"); @@ -65,15 +78,14 @@ void connectToWifi() { } -const char GreeterText[] = "Reddit | Showerthoughts"; +const char TitleText[] = "Reddit | Showerthoughts"; void DisplayShowerthought() { - Serial.println("DEBUG: Showing greeting screen"); - //display.setRotation(3); + Serial.println("DEBUG: Printing Showerthought to display"); display.setFont(&FreeMonoBold9pt7b); display.setTextColor(GxEPD_BLACK); int16_t tbx, tby; uint16_t tbw, tbh; - display.getTextBounds(GreeterText, 0, 0, &tbx, &tby, &tbw, &tbh); + display.getTextBounds(TitleText, 0, 0, &tbx, &tby, &tbw, &tbh); uint16_t x = ((display.width() - tbw) / 2) - tbx; uint16_t y = ((display.height() - tbh) / 2) - tby; display.setFullWindow(); @@ -83,7 +95,7 @@ void DisplayShowerthought() { display.fillScreen(GxEPD_WHITE); display.drawBitmap(130, 90, logo, 125, 125, GxEPD_BLACK); display.setCursor(x, y); - display.print(GreeterText); + display.print(TitleText); display.drawRect(x-16, y-20, tbw+32, tbh+18, GxEPD_BLACK); display.setCursor(0, 450); display.print(Thought);