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
[common]
version = "3.0.9"
to_old_version = "2.0.10"
version = "3.1.0"
to_old_version = "3.0.9"
##
[env:esp32dev]
+21 -3
View File
@@ -100,24 +100,42 @@ 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
bool showingConnError = false;
unsigned long connErrorStartTime = 0;
const unsigned long connErrorDisplayDuration = 3000;
// ##### PROGRAM START #####
void loop() {
unsigned long currentMillis = millis();
// Handle connection errors (not registered or not connected)
if (intervalElapsed(currentMillis, lastConnErrorShowTime, connErrorShowInterval)) {
if (!showingConnError && intervalElapsed(currentMillis, lastConnErrorShowTime, connErrorShowInterval)) {
if (!filamanRegistered) {
oledShowConnectionError("Not Registered", WiFi.localIP().toString());
vTaskDelay(pdMS_TO_TICKS(3000));
showingConnError = true;
connErrorStartTime = currentMillis;
mainTaskWasPaused = true;
} else if (!filamanConnected) {
oledShowConnectionError("API Connection Lost", WiFi.localIP().toString());
vTaskDelay(pdMS_TO_TICKS(3000));
showingConnError = true;
connErrorStartTime = currentMillis;
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
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;
void wifiSettings() {
// Optimierte WiFi-Einstellungen
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
WiFi.setSleep(false); // disable sleep mode
// Standard WiFi-Einstellungen für höchste Stabilität mit ESPAsyncWebServer
WiFi.mode(WIFI_STA);
WiFi.setHostname("FilaMan");
esp_wifi_set_ps(WIFI_PS_NONE);
// Maximale Sendeleistung
WiFi.setTxPower(WIFI_POWER_19_5dBm); // Set maximum transmit power
// Wir lassen das Power Management (Sleep) auf dem ESP-Standard.
// Ein erzwungenes Ausschalten führt zu RF-Abstürzen bei vielen asynchronen HTTP-Requests.
// Angemessene Sendeleistung (reduziert Hitzeprobleme)
WiFi.setTxPower(WIFI_POWER_17dBm); // Set stable transmit power (default is 19.5 which gets hot)
// Optimiere TCP/IP Stack
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
// Wir überlassen die Protokoll-Aushandlung (b/g/n) dem Treiber. Harte Vorgaben crashen unter Last.
// Aktiviere WiFi-Roaming für bessere Stabilität
esp_wifi_set_rssi_threshold(-80);
@@ -74,37 +74,33 @@ void initWiFi() {
void checkWiFiConnection() {
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("WiFi connection lost. Reconnecting...");
wifiOn = false;
oledShowTopRow();
oledDisplayText("WiFi reconnecting");
WiFi.reconnect(); // Versuche, die Verbindung wiederherzustellen
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++;
if (wifiOn) {
Serial.println("WiFi connection lost. LwIP is auto-reconnecting...");
wifiOn = false;
oledShowTopRow();
oledDisplayText("WiFi reconnecting");
}
wifiErrorCounter++;
//wifiSettings();
WiFi.reconnect();
Serial.println("WiFi reconnecting...");
WiFi.waitForConnectResult();
}
else
// 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.");
wifiErrorCounter = 0;
wifiOn = true;
oledShowTopRow();
Serial.println("WiFi unable to reconnect for 5 minutes. Restarting...");
ESP.restart();
}
}
if (wifiErrorCounter >= 5)
else
{
Serial.println("Too many WiFi errors. Restarting...");
ESP.restart();
if (!wifiOn) {
Serial.println("WiFi reconnected.");
wifiErrorCounter = 0;
wifiOn = true;
oledShowTopRow();
} else {
// Reset error counter if we are connected (just to be safe)
wifiErrorCounter = 0;
}
}
}