chore: cleanup progress bar during setup

This commit is contained in:
anderl1969 committed 2026-03-29 13:56:29 +02:00
1 parent 6de2e8728c
commit f09e552e3d
10 files changed
+371 -360

No files matched your search

+7 -6
View File
@@ -136,7 +136,7 @@ bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
Serial.printf("API payload: %s\n", payload.c_str());
int httpCode = http.POST(payload);
Serial.printf("API response code: %d\n", httpCode);
if (httpCode == 200) {
String response = http.getString();
JsonDocument responseDoc;
@@ -157,7 +157,7 @@ bool sendWeight(int spoolId, String tagUuid, float measuredWeight) {
vTaskDelay(pdMS_TO_TICKS(2000));
oledClearPriority();
}
http.end();
return false;
}
@@ -192,7 +192,7 @@ bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, S
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", "Device " + filamanToken);
http.addHeader("Connection", "keep-alive");
JsonDocument doc;
doc["success"] = success;
if (tagUuid.length() > 0) doc["tag_uuid"] = tagUuid;
@@ -200,7 +200,7 @@ bool sendRfidResult(String tagUuid, int spoolId, int locationId, bool success, S
if (locationId > 0) doc["location_id"] = locationId;
if (errorMessage.length() > 0) doc["error_message"] = errorMessage;
if (remainingWeight > 0) doc["remaining_weight_g"] = remainingWeight;
String payload;
serializeJson(doc, payload);
int httpCode = http.POST(payload);
@@ -212,7 +212,7 @@ void filamanApiTask(void* pvParameters) {
for (;;) {
ApiRequest req;
bool hasReq = false;
if (xSemaphoreTake(queueMutex, pdMS_TO_TICKS(100)) == pdTRUE) {
for(int i=0; i<MAX_API_QUEUE; i++) {
if(apiQueue[i].active) {
@@ -324,11 +324,12 @@ void sendRfidResultAsync(String tagUuid, int spoolId, int locationId, bool succe
}
bool initFilaman() {
oledShowProgressBar(3, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_API_INIT));
loadFilamanConfig();
queueMutex = xSemaphoreCreateMutex();
// Move to Core 1 (Hardware Core) to free up Core 0 for WiFi/Webserver
// Set priority to 1 (same as Scale/NFC) to ensure fair scheduling
xTaskCreatePinnedToCore(filamanApiTask, "FilaManApi", 6144, NULL, 1, NULL, 1);
xTaskCreatePinnedToCore(filamanApiTask, "FilaManApi", 6144, NULL, 1, NULL, 1);
if (checkFilamanRegistration()) sendHeartbeatAsync();
return true;
}
+3 -1
View File
@@ -29,6 +29,8 @@
#define DISPLAY_UPDATE_INTERVAL 1000U
#define FILAMAN_HEARTBEAT_INTERVAL 60000U
#define NUM_SETUP_STEPS 6 // 0:Display 1:WiFi 2:Web-Server 3:API 4:NFC 5:Scale 6:<finished>
extern const uint8_t PN532_IRQ;
extern const uint8_t PN532_RESET;
@@ -72,4 +74,4 @@ extern uint8_t scaleTaskPrio;
extern uint16_t defaultScaleCalibrationValue;
extern uint16_t oledSleepTimeout;
#endif
#endif
+21 -21
View File
@@ -115,7 +115,7 @@ void setupDisplay() {
lastActivityMillis = millis();
oledShowTopRow();
oledShowProgressBar(0, 7, DISPLAY_BOOT_TEXT, tr(STR_DISPLAY_INIT));
oledShowProgressBar(0, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_DISPLAY_INIT));
}
void oledclearline() {
@@ -144,14 +144,14 @@ int oled_center_v(const String &text) {
std::vector<String> splitTextIntoLines(const String &text, uint8_t textSize) {
std::vector<String> lines;
display.setTextSize(textSize);
// Text in Wörter aufteilen
std::vector<String> words;
int pos = 0;
while (pos < text.length()) {
// Überspringe Leerzeichen am Anfang
while (pos < text.length() && text[pos] == ' ') pos++;
// Finde nächstes Leerzeichen
int nextSpace = text.indexOf(' ', pos);
if (nextSpace == -1) {
@@ -165,19 +165,19 @@ std::vector<String> splitTextIntoLines(const String &text, uint8_t textSize) {
words.push_back(text.substring(pos, nextSpace));
pos = nextSpace + 1;
}
// Wörter zu Zeilen zusammenfügen
String currentLine = "";
for (size_t i = 0; i < words.size(); i++) {
String testLine = currentLine;
if (currentLine.length() > 0) testLine += " ";
testLine += words[i];
// Prüfe ob diese Kombination auf die Zeile passt
int16_t x1, y1;
uint16_t lineWidth, h;
display.getTextBounds(testLine, 0, OLED_DATA_START, &x1, &y1, &lineWidth, &h);
if (lineWidth <= SCREEN_WIDTH) {
// Passt noch in diese Zeile
currentLine = testLine;
@@ -192,40 +192,40 @@ std::vector<String> splitTextIntoLines(const String &text, uint8_t textSize) {
}
}
}
// Letzte Zeile hinzufügen
if (currentLine.length() > 0) {
lines.push_back(currentLine);
}
return lines;
}
void oledShowMultilineMessage(const String &message, uint8_t size) {
std::vector<String> lines;
int maxLines = 3; // Maximale Anzahl Zeilen für size 2
// Erste Prüfung mit aktueller Größe
lines = splitTextIntoLines(message, size);
// Wenn mehr als maxLines Zeilen, reduziere Textgröße
if (lines.size() > maxLines && size > 1) {
size = 1;
lines = splitTextIntoLines(message, size);
}
// Ausgabe
display.setTextSize(size);
int lineHeight = size * 8;
int totalHeight = lines.size() * lineHeight;
int startY = OLED_DATA_START + ((OLED_DATA_END - OLED_DATA_START - totalHeight) / 2);
uint8_t lineDistance = (lines.size() == 2) ? 5 : 0;
for (size_t i = 0; i < lines.size(); i++) {
display.setCursor(oled_center_h(lines[i]), startY + (i * lineHeight) + (i == 1 ? lineDistance : 0));
display.print(lines[i]);
}
display.display();
}
@@ -233,12 +233,12 @@ void oledDisplayText(const String &message, uint8_t size) {
oledcleardata();
display.setTextSize(size);
display.setTextWrap(false);
// Prüfe ob Text in eine Zeile passt
int16_t x1, y1;
uint16_t textWidth, h;
display.getTextBounds(message, 0, 0, &x1, &y1, &textWidth, &h);
// Text passt in eine Zeile?
if (textWidth <= SCREEN_WIDTH) {
display.setCursor(oled_center_h(message), oled_center_v(message));
@@ -281,7 +281,7 @@ void oledShowTopRow() {
}
}
}
display.display();
}
@@ -313,7 +313,7 @@ void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char*
// clear data and bar area
display.fillRect(0, OLED_DATA_START, SCREEN_WIDTH, SCREEN_HEIGHT-16, BLACK);
display.setTextWrap(false);
display.setTextSize(2);
display.setCursor(0, OLED_DATA_START+4);
@@ -343,7 +343,7 @@ void oledShowRemainingWeight(uint16_t remainingWeight) {
display.setTextSize(1);
display.setCursor(oled_center_h(tr(STR_WEIGHT_SENT_REST)), OLED_DATA_START + 4);
display.print(tr(STR_WEIGHT_SENT_REST));
display.setTextSize(3);
String weightStr = String(remainingWeight) + " g";
display.setCursor(oled_center_h(weightStr), OLED_DATA_START + 22);
@@ -354,15 +354,15 @@ void oledShowRemainingWeight(uint16_t remainingWeight) {
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();
}
+4
View File
@@ -10,8 +10,10 @@ Lang currentLang = LANG_EN;
static const char EN_DISPLAY_INIT[] = "Display init";
static const char EN_WIFI_INIT[] = "WiFi init";
static const char EN_WEBSERVER_INIT[] = "Webserver init";
static const char EN_API_INIT[] = "API init";
static const char EN_NFC_INIT[] = "NFC init";
static const char EN_SEARCHING_SCALE[] = "Searching scale";
static const char EN_INIT_DONE[] = "Setup finished";
static const char EN_TARE_SCALE[] = "TARE Scale";
static const char EN_SCALE_NOT_CAL[] = "Scale not calibrated";
@@ -82,8 +84,10 @@ static const char EN_DOWNLOAD[] = "Download";
static const char DE_DISPLAY_INIT[] = "Display init";
static const char DE_WIFI_INIT[] = "WiFi init";
static const char DE_WEBSERVER_INIT[] = "Webserver init";
static const char DE_API_INIT[] = "API init";
static const char DE_NFC_INIT[] = "NFC init";
static const char DE_SEARCHING_SCALE[] = "Suche Waage";
static const char DE_INIT_DONE[] = "Setup abgeschlossen";
static const char DE_TARE_SCALE[] = "Waage tarieren";
static const char DE_SCALE_NOT_CAL[] = "Waage nicht kalibriert";
+2
View File
@@ -16,8 +16,10 @@ enum StringID : uint8_t {
STR_DISPLAY_INIT,
STR_WIFI_INIT,
STR_WEBSERVER_INIT,
STR_API_INIT,
STR_NFC_INIT,
STR_SEARCHING_SCALE,
STR_INIT_DONE,
// Scale
STR_TARE_SCALE,
+19 -17
View File
@@ -53,7 +53,7 @@ void setup() {
// Touch Sensor
pinMode(TTP223_PIN, INPUT_PULLUP);
if (digitalRead(TTP223_PIN) == LOW)
if (digitalRead(TTP223_PIN) == LOW)
{
Serial.println("Touch Sensor is connected");
touchSensorConnected = true;
@@ -68,6 +68,8 @@ void setup() {
esp_task_wdt_init(10, panic);
booting = false;
oledShowProgressBar(6, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_INIT_DONE));
// Aktuellen Task (loopTask) zum Watchdog hinzufügen
esp_task_wdt_add(NULL);
}
@@ -123,7 +125,7 @@ void loop() {
}
// Überprüfe den Status des Touch Sensors
if (touchSensorConnected && digitalRead(TTP223_PIN) == HIGH && currentMillis - lastButtonPress > debounceDelay)
if (touchSensorConnected && digitalRead(TTP223_PIN) == HIGH && currentMillis - lastButtonPress > debounceDelay)
{
lastButtonPress = currentMillis;
scaleTareRequest = true;
@@ -131,18 +133,18 @@ void loop() {
}
// Überprüfe regelmäßig die WLAN-Verbindung
if (intervalElapsed(currentMillis, lastWifiCheckTime, WIFI_CHECK_INTERVAL))
if (intervalElapsed(currentMillis, lastWifiCheckTime, WIFI_CHECK_INTERVAL))
{
checkWiFiConnection();
}
// Periodic display update
if (intervalElapsed(currentMillis, lastTopRowUpdateTime, DISPLAY_UPDATE_INTERVAL))
if (intervalElapsed(currentMillis, lastTopRowUpdateTime, DISPLAY_UPDATE_INTERVAL))
{
oledShowTopRow();
oledCheckSleep(); // Put display to sleep if timeout elapsed
}
// WebSocket Cleanup alle 5 Sekunden (häufiger als vorher)
// Tote Clients können WiFi-Ressourcen blockieren
static unsigned long lastWsCleanup = 0;
@@ -152,21 +154,21 @@ void loop() {
}
// Periodic FilaMan heartbeat
if (intervalElapsed(currentMillis, lastFilamanHeartbeatTime, FILAMAN_HEARTBEAT_INTERVAL))
if (intervalElapsed(currentMillis, lastFilamanHeartbeatTime, FILAMAN_HEARTBEAT_INTERVAL))
{
sendHeartbeatAsync();
}
// If scale is not calibrated, only show a warning
if (!scaleCalibrated)
if (!scaleCalibrated)
{
// Do not show the warning if the calibratin process is onging
if(!scaleCalibrationActive){
oledDisplayText(tr(STR_SCALE_NOT_CALIBRATED));
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
else
}
else
{
// Ausgabe der Waage auf Display
// Block weight display during NFC write operations and higher-priority display messages
@@ -201,8 +203,8 @@ void loop() {
oledShowProgressBar(2, 4, tr(STR_SPOOL_TAG), tr(STR_WEIGHT_STABLE));
oledSetPriority(DISPLAY_PRIORITY_INFO, 1000);
}
}
else
}
else
{
// Show visual feedback when tag is present and weight is unstable
if (weightCounterToApi > 0 && nfcReaderState == NFC_READ_SUCCESS && !tagProcessed && weightSend == 0) {
@@ -216,10 +218,10 @@ void loop() {
lastWeight = weight;
// Wenn ein Tag erkannt wurde und das Gewicht stabil ist (4+ seconds), an FilaMan senden
if (weightCounterToApi > 3 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS && tagProcessed == false)
if (weightCounterToApi > 3 && weightSend == 0 && nfcReaderState == NFC_READ_SUCCESS && tagProcessed == false)
{
tagProcessed = true;
// Check if it's a Bambu tag - if so, send only UUID without spoolId
if (isBambuTag) {
sendWeightAsync(0, activeTagUuid, weight);
@@ -231,24 +233,24 @@ void loop() {
Serial.println("Weight queued for FilaMan");
}
weightSend = 1;
// Feedback to user
oledShowProgressBar(3, 4, tr(STR_SPOOL_TAG), tr(STR_SENDING));
oledSetPriority(DISPLAY_PRIORITY_ACTION, 2000);
}
// Handle successful tag write
if (nfcReaderState == NFC_WRITE_SUCCESS && tagProcessed == false)
if (nfcReaderState == NFC_WRITE_SUCCESS && tagProcessed == false)
{
tagProcessed = true;
// Only send weight if a valid spoolId exists (spool tag, not location tag)
if (activeSpoolId.length() > 0 && activeSpoolId != "0") {
int sId = activeSpoolId.toInt();
sendWeightAsync(sId, activeTagUuid, weight);
weightSend = 1;
Serial.println("Weight queued for FilaMan after spool tag write");
// Feedback to user
oledShowProgressBar(3, 4, tr(STR_TAG_WRITTEN), tr(STR_SENDING));
oledSetPriority(DISPLAY_PRIORITY_ACTION, 2000);
+267 -267
View File
File diff suppressed because it is too large. Load diff
+29 -29
View File
@@ -50,7 +50,7 @@ void resetWeightFilter() {
filteredWeight = 0.0f;
lastDisplayedWeight = 0;
lastStableWeight = 0; // Reset stable weight for API actions
// Initialize buffer with zeros
for (int i = 0; i < MOVING_AVERAGE_SIZE; i++) {
weightBuffer[i] = 0.0f;
@@ -63,11 +63,11 @@ void resetWeightFilter() {
float calculateMovingAverage() {
float sum = 0.0f;
int count = bufferFilled ? MOVING_AVERAGE_SIZE : bufferIndex;
for (int i = 0; i < count; i++) {
sum += weightBuffer[i];
}
return (count > 0) ? sum / count : 0.0f;
}
@@ -88,33 +88,33 @@ int16_t processWeightReading(float rawWeight) {
// Add to moving average buffer
weightBuffer[bufferIndex] = rawWeight;
bufferIndex = (bufferIndex + 1) % MOVING_AVERAGE_SIZE;
if (bufferIndex == 0) {
bufferFilled = true;
}
// Calculate moving average
float avgWeight = calculateMovingAverage();
// Apply low-pass filter
float smoothedWeight = applyLowPassFilter(avgWeight);
// Round to nearest gram
int16_t newWeight = round(smoothedWeight);
// Update displayed weight if display threshold is reached
if (abs(newWeight - lastDisplayedWeight) >= DISPLAY_THRESHOLD) {
lastDisplayedWeight = newWeight;
}
// Update global weight for API actions only if stable threshold is reached
int16_t weightToReturn = weight; // Default: keep current weight
if (abs(newWeight - lastStableWeight) >= API_THRESHOLD) {
lastStableWeight = newWeight;
weightToReturn = newWeight;
}
return weightToReturn;
}
@@ -145,7 +145,7 @@ uint8_t tareScale() {
Serial.println("Tare scale");
scale.tare();
resetWeightFilter();
return 1;
}
@@ -161,13 +161,13 @@ void scale_loop(void * parameter) {
for(;;) {
unsigned long currentTime = millis();
// Only measure at defined intervals to reduce noise
if (currentTime - lastMeasurementTime >= MEASUREMENT_INTERVAL_MS) {
if (scale.is_ready())
if (scale.is_ready())
{
// Waage manuell Taren
if (scaleTareRequest == true || (autoTare && scale_tare_counter >= 20))
if (scaleTareRequest == true || (autoTare && scale_tare_counter >= 20))
{
Serial.println("Re-Tare scale");
oledDisplayText(tr(STR_TARE_SCALE));
@@ -189,16 +189,16 @@ void scale_loop(void * parameter) {
// Get raw weight reading
float rawWeight = scale.get_units();
// Process weight with stabilization
int16_t stabilizedWeight = processWeightReading(rawWeight);
// Update global weight variable only if it changed significantly (for API actions)
if (stabilizedWeight != weight) {
weight = stabilizedWeight;
oledResetActivityTimer(); // Wake display on weight change
}
// Prüfen ob die Waage korrekt genullt ist
// Abweichung von 2g ignorieren
if (autoTare && (rawWeight > 2 && rawWeight < 7) || rawWeight < -2)
@@ -215,11 +215,11 @@ void scale_loop(void * parameter) {
if (currentTime - lastDebugTime > 2000) { // Print every 2 seconds
lastDebugTime = currentTime;
}
lastMeasurementTime = currentTime;
}
}
vTaskDelay(pdMS_TO_TICKS(10)); // Shorter delay for more responsive loop
}
}
@@ -238,7 +238,7 @@ void start_scale(bool touchSensorConnected) {
calibrationValue = SCALE_DEFAULT_CALIBRATION_VALUE;
scaleCalibrated = false;
}
// auto Tare
// Wenn Touch Sensor verbunden, dann autoTare auf false setzen
// Danach prüfen was in NVS gespeichert ist
@@ -252,7 +252,7 @@ void start_scale(bool touchSensorConnected) {
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
oledShowProgressBar(6, 7, DISPLAY_BOOT_TEXT, tr(STR_SEARCHING_SCALE));
oledShowProgressBar(5, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_SEARCHING_SCALE));
for (uint16_t i = 0; i < 3000; i++) {
yield();
vTaskDelay(pdMS_TO_TICKS(1));
@@ -300,10 +300,10 @@ uint8_t calibrate_scale() {
if (ScaleTask != NULL && xTaskGetCurrentTaskHandle() != ScaleTask) vTaskSuspend(ScaleTask);
pauseMainTask = 1;
if (scale.wait_ready_timeout(1000))
{
scale.set_scale();
oledShowProgressBar(0, 3, tr(STR_SCALE_CAL), tr(STR_EMPTY_SCALE));
@@ -324,7 +324,7 @@ uint8_t calibrate_scale() {
vTaskDelay(pdMS_TO_TICKS(1));
esp_task_wdt_reset();
}
float newCalibrationValue = scale.get_units(10);
Serial.print("Result: ");
Serial.println(newCalibrationValue);
@@ -359,7 +359,7 @@ uint8_t calibrate_scale() {
vTaskDelay(pdMS_TO_TICKS(1));
esp_task_wdt_reset();
}
oledShowProgressBar(3, 3, tr(STR_SCALE_CAL), tr(STR_COMPLETED));
// For some reason it is not possible to re-tare the scale here, it will result in a wdt timeout. Instead let the scale loop do the taring
@@ -387,12 +387,12 @@ uint8_t calibrate_scale() {
esp_task_wdt_reset();
}
returnState = 0;
}
}
}
else
else
{
Serial.println("HX711 not found.");
oledDisplayText(tr(STR_HX711_NOT_FOUND));
for (uint16_t i = 0; i < 30000; i++) {
+5 -5
View File
@@ -124,8 +124,8 @@ void sendNfcData() {
}
void setupWebserver(AsyncWebServer &server) {
oledShowProgressBar(2, 7, DISPLAY_BOOT_TEXT, tr(STR_WEBSERVER_INIT));
oledShowProgressBar(2, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_WEBSERVER_INIT));
ws.onEvent(onWsEvent);
server.addHandler(&ws);
@@ -138,7 +138,7 @@ void setupWebserver(AsyncWebServer &server) {
.setCacheControl(CACHE_ASSETS);
server.serveStatic("/favicon.ico", LittleFS, "/favicon.ico")
.setCacheControl(CACHE_ASSETS);
// ===== STATISCHE HTML-SEITEN (ohne Template-Ersetzung) =====
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
Serial.println("Web: Request /");
@@ -214,7 +214,7 @@ void setupWebserver(AsyncWebServer &server) {
String payloadString;
serializeJson(doc, payloadString);
bool hasSpoolId = !doc["spool_id"].isNull() || !doc["sm_id"].isNull();
int spoolId = doc["spool_id"] | 0;
if (spoolId == 0 && doc["sm_id"].is<String>()) {
@@ -223,7 +223,7 @@ void setupWebserver(AsyncWebServer &server) {
int locationId = doc["location_id"] | 0;
startWriteJsonToTag(hasSpoolId, payloadString.c_str(), spoolId, locationId);
// Respond immediately
request->send(200, "application/json", "{\"success\": true, \"message\": \"Schreibvorgang wurde gestartet. Bitte Tag bereit halten...\"}");
});
+14 -14
View File
@@ -14,17 +14,17 @@ uint8_t wifiErrorCounter = 0;
void wifiSettings() {
// Standard WiFi-Einstellungen für höchste Stabilität mit ESPAsyncWebServer
WiFi.mode(WIFI_STA);
WiFi.mode(WIFI_STA);
WiFi.setHostname("FilaMan");
// KRITISCH: Power-Save deaktivieren für stabilen Webserver-Betrieb
// Ohne dies geht WiFi in Modem-Sleep und verpasst Requests/Responses
// Dies ist die Hauptursache für Verbindungsabbrüche bei regelmäßigen API-Calls
esp_wifi_set_ps(WIFI_PS_NONE);
// Angemessene Sendeleistung (reduziert Hitzeprobleme)
WiFi.setTxPower(WIFI_POWER_17dBm);
// Aktiviere WiFi-Roaming für bessere Stabilität bei schwachem Signal
esp_wifi_set_rssi_threshold(-80);
}
@@ -51,19 +51,19 @@ void initWiFi() {
wm.setWiFiAutoReconnect(true);
wm.setConnectTimeout(10);
oledShowProgressBar(1, 7, DISPLAY_BOOT_TEXT, tr(STR_WIFI_INIT));
oledShowProgressBar(1, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_WIFI_INIT));
//bool res = wm.autoConnect("FilaMan"); // anonymous ap
if(!wm.autoConnect("FilaMan")) {
Serial.println("Failed to connect or hit timeout");
// ESP.restart();
oledShowTopRow();
oledDisplayText(tr(STR_WIFI_NOT_CONNECTED));
}
}
else {
wifiOn = true;
//if you get here you have connected to the WiFi
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
@@ -73,23 +73,23 @@ void initWiFi() {
}
void checkWiFiConnection() {
if (WiFi.status() != WL_CONNECTED)
if (WiFi.status() != WL_CONNECTED)
{
if (wifiOn) {
Serial.println("WiFi connection lost. Attempting active reconnect...");
wifiOn = false;
oledShowTopRow();
oledDisplayText(tr(STR_WIFI_RECONNECTING));
// Aktiver Reconnect-Versuch statt nur auf LwIP auto-reconnect zu warten
WiFi.reconnect();
}
wifiErrorCounter++;
// Only restart after a significant time of no connection (e.g. 5 minutes)
// Assuming WIFI_CHECK_INTERVAL is 60000ms (1 minute), 5 errors = 5 minutes
if (wifiErrorCounter >= 5)
if (wifiErrorCounter >= 5)
{
Serial.println("WiFi unable to reconnect for 5 minutes. Restarting...");
ESP.restart();
@@ -102,7 +102,7 @@ void checkWiFiConnection() {
wifiErrorCounter = 0;
wifiOn = true;
oledShowTopRow();
// Power-Save erneut deaktivieren nach Reconnect (wird manchmal zurückgesetzt)
esp_wifi_set_ps(WIFI_PS_NONE);
} else {
@@ -110,4 +110,4 @@ void checkWiFiConnection() {
wifiErrorCounter = 0;
}
}
}
}