diff --git a/src/display.cpp b/src/display.cpp index be9b50b..aadbbcc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -253,3 +253,19 @@ void oledShowWeight(uint16_t weight) { display.print(" g"); display.display(); } + +void oledShowConnectionError(const char* error, const String& ip) { + oledcleardata(); + display.setTextSize(1); + + // Error Message + display.setCursor(oled_center_h(error), OLED_DATA_START + 4); + display.print(error); + + // IP Address + display.setTextSize(1); + display.setCursor(oled_center_h(ip), OLED_DATA_START + 24); + display.print(ip); + + display.display(); +} diff --git a/src/display.h b/src/display.h index 06e55a7..0bf736d 100644 --- a/src/display.h +++ b/src/display.h @@ -20,6 +20,7 @@ void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* void oledShowWeight(uint16_t weight); void oledDisplayText(const String &message, uint8_t size = 2); +void oledShowConnectionError(const char* error, const String& ip); void oledShowTopRow(); void oledShowIcon(const char* icon); diff --git a/src/main.cpp b/src/main.cpp index 8e9a87c..afd28e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,10 +98,26 @@ int16_t lastWeight = 0; unsigned long lastButtonPress = 0; const unsigned long debounceDelay = 500; // 500 ms debounce delay +unsigned long lastConnErrorShowTime = 0; +const unsigned long connErrorShowInterval = 10000; // Show connection error every 10 seconds if exists + // ##### PROGRAM START ##### void loop() { unsigned long currentMillis = millis(); + // Handle connection errors (not registered or not connected) + if (intervalElapsed(currentMillis, lastConnErrorShowTime, connErrorShowInterval)) { + if (!filamanRegistered) { + oledShowConnectionError("Not Registered", WiFi.localIP().toString()); + vTaskDelay(pdMS_TO_TICKS(3000)); + mainTaskWasPaused = true; + } else if (!filamanConnected) { + oledShowConnectionError("API Connection Lost", WiFi.localIP().toString()); + vTaskDelay(pdMS_TO_TICKS(3000)); + mainTaskWasPaused = true; + } + } + // Überprüfe den Status des Touch Sensors if (touchSensorConnected && digitalRead(TTP223_PIN) == HIGH && currentMillis - lastButtonPress > debounceDelay) { diff --git a/src/wlan.cpp b/src/wlan.cpp index 09ff61f..1d221c9 100644 --- a/src/wlan.cpp +++ b/src/wlan.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include "display.h" #include "config.h" @@ -29,17 +28,6 @@ void wifiSettings() { esp_wifi_set_rssi_threshold(-80); } -void startMDNS() { - if (!MDNS.begin("filaman")) { - Serial.println("Error setting up MDNS responder!"); - while(1) { - vTaskDelay(pdMS_TO_TICKS(1000)); - } - } - MDNS.addService("http", "tcp", 80); - Serial.println("mDNS responder started"); -} - void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); oledShowTopRow(); @@ -80,9 +68,6 @@ void initWiFi() { Serial.println(WiFi.localIP()); oledShowTopRow(); - - // mDNS - startMDNS(); } } @@ -114,7 +99,6 @@ void checkWiFiConnection() { wifiErrorCounter = 0; wifiOn = true; oledShowTopRow(); - startMDNS(); } }