Compare commits

..
3 Commits
3 changed files with 54 additions and 40 deletions

No files matched your search

+2 -2
View File
@@ -9,8 +9,8 @@
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[common] [common]
version = "3.0.9" version = "3.1.0"
to_old_version = "2.0.10" to_old_version = "3.0.9"
## ##
[env:esp32dev] [env:esp32dev]
+21 -3
View File
@@ -100,24 +100,42 @@ const unsigned long debounceDelay = 500; // 500 ms debounce delay
unsigned long lastConnErrorShowTime = 0; unsigned long lastConnErrorShowTime = 0;
const unsigned long connErrorShowInterval = 10000; // Show connection error every 10 seconds if exists const unsigned long connErrorShowInterval = 10000; // Show connection error every 10 seconds if exists
bool showingConnError = false;
unsigned long connErrorStartTime = 0;
const unsigned long connErrorDisplayDuration = 3000;
// ##### PROGRAM START ##### // ##### PROGRAM START #####
void loop() { void loop() {
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
// Handle connection errors (not registered or not connected) // Handle connection errors (not registered or not connected)
if (intervalElapsed(currentMillis, lastConnErrorShowTime, connErrorShowInterval)) { if (!showingConnError && intervalElapsed(currentMillis, lastConnErrorShowTime, connErrorShowInterval)) {
if (!filamanRegistered) { if (!filamanRegistered) {
oledShowConnectionError("Not Registered", WiFi.localIP().toString()); oledShowConnectionError("Not Registered", WiFi.localIP().toString());
vTaskDelay(pdMS_TO_TICKS(3000)); showingConnError = true;
connErrorStartTime = currentMillis;
mainTaskWasPaused = true; mainTaskWasPaused = true;
} else if (!filamanConnected) { } else if (!filamanConnected) {
oledShowConnectionError("API Connection Lost", WiFi.localIP().toString()); oledShowConnectionError("API Connection Lost", WiFi.localIP().toString());
vTaskDelay(pdMS_TO_TICKS(3000)); showingConnError = true;
connErrorStartTime = currentMillis;
mainTaskWasPaused = true; mainTaskWasPaused = true;
} }
} }
// Clear connection error after duration
if (showingConnError && currentMillis - connErrorStartTime >= connErrorDisplayDuration) {
showingConnError = false;
// Force UI refresh next cycle
lastTopRowUpdateTime = 0;
}
// Skip the rest of the loop while showing error to avoid UI overwriting
if (showingConnError) {
esp_task_wdt_reset();
return;
}
// Überprüfe den Status des Touch Sensors // Ü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)
{ {
+31 -35
View File
@@ -12,17 +12,17 @@ bool wm_nonblocking = false;
uint8_t wifiErrorCounter = 0; uint8_t wifiErrorCounter = 0;
void wifiSettings() { void wifiSettings() {
// Optimierte WiFi-Einstellungen // Standard WiFi-Einstellungen für höchste Stabilität mit ESPAsyncWebServer
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP WiFi.mode(WIFI_STA);
WiFi.setSleep(false); // disable sleep mode
WiFi.setHostname("FilaMan"); WiFi.setHostname("FilaMan");
esp_wifi_set_ps(WIFI_PS_NONE);
// Maximale Sendeleistung // Wir lassen das Power Management (Sleep) auf dem ESP-Standard.
WiFi.setTxPower(WIFI_POWER_19_5dBm); // Set maximum transmit power // Ein erzwungenes Ausschalten führt zu RF-Abstürzen bei vielen asynchronen HTTP-Requests.
// Optimiere TCP/IP Stack // Angemessene Sendeleistung (reduziert Hitzeprobleme)
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N); WiFi.setTxPower(WIFI_POWER_17dBm); // Set stable transmit power (default is 19.5 which gets hot)
// Wir überlassen die Protokoll-Aushandlung (b/g/n) dem Treiber. Harte Vorgaben crashen unter Last.
// Aktiviere WiFi-Roaming für bessere Stabilität // Aktiviere WiFi-Roaming für bessere Stabilität
esp_wifi_set_rssi_threshold(-80); esp_wifi_set_rssi_threshold(-80);
@@ -74,37 +74,33 @@ void initWiFi() {
void checkWiFiConnection() { void checkWiFiConnection() {
if (WiFi.status() != WL_CONNECTED) if (WiFi.status() != WL_CONNECTED)
{ {
Serial.println("WiFi connection lost. Reconnecting..."); if (wifiOn) {
wifiOn = false; Serial.println("WiFi connection lost. LwIP is auto-reconnecting...");
oledShowTopRow(); wifiOn = false;
oledDisplayText("WiFi reconnecting"); oledShowTopRow();
WiFi.reconnect(); // Versuche, die Verbindung wiederherzustellen oledDisplayText("WiFi reconnecting");
vTaskDelay(pdMS_TO_TICKS(5000)); // Warte 5 Sekunden, bevor erneut geprüft wird
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("Failed to reconnect. Restarting WiFi...");
WiFi.disconnect();
Serial.println("WiFi disconnected.");
vTaskDelay(pdMS_TO_TICKS(1000));
wifiErrorCounter++;
//wifiSettings();
WiFi.reconnect();
Serial.println("WiFi reconnecting...");
WiFi.waitForConnectResult();
} }
else
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)
{ {
Serial.println("WiFi reconnected."); Serial.println("WiFi unable to reconnect for 5 minutes. Restarting...");
wifiErrorCounter = 0; ESP.restart();
wifiOn = true;
oledShowTopRow();
} }
} }
else
if (wifiErrorCounter >= 5)
{ {
Serial.println("Too many WiFi errors. Restarting..."); if (!wifiOn) {
ESP.restart(); Serial.println("WiFi reconnected.");
wifiErrorCounter = 0;
wifiOn = true;
oledShowTopRow();
} else {
// Reset error counter if we are connected (just to be safe)
wifiErrorCounter = 0;
}
} }
} }