Add connection error handling to display: show error messages for registration and API connection issues
This commit is contained in:
1 parent
f29e6aeded
commit
86973c07ec
4 files changed
+33
-16
No files matched your search
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <esp_wifi.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESPmDNS.h>
|
||||
#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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user