feat: füge regelmäßige WLAN-Verbindungsüberprüfung hinzu
This commit is contained in:
parent
c645035bbe
commit
46cd953b80
10
src/main.cpp
10
src/main.cpp
@ -100,12 +100,20 @@ const unsigned long amsSendInterval = 60000; // 1 minute
|
|||||||
|
|
||||||
uint8_t weightSend = 0;
|
uint8_t weightSend = 0;
|
||||||
int16_t lastWeight = 0;
|
int16_t lastWeight = 0;
|
||||||
uint8_t wifiErrorCounter = 0;
|
|
||||||
|
unsigned long lastWifiCheckTime = 0;
|
||||||
|
const unsigned long wifiCheckInterval = 60000; // Überprüfe alle 60 Sekunden (60000 ms)
|
||||||
|
|
||||||
// ##### PROGRAM START #####
|
// ##### PROGRAM START #####
|
||||||
void loop() {
|
void loop() {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
|
|
||||||
|
// Überprüfe regelmäßig die WLAN-Verbindung
|
||||||
|
if (millis() - lastWifiCheckTime > wifiCheckInterval) {
|
||||||
|
checkWiFiConnection();
|
||||||
|
lastWifiCheckTime = millis();
|
||||||
|
}
|
||||||
|
|
||||||
// Send AMS Data min every Minute
|
// Send AMS Data min every Minute
|
||||||
if (currentMillis - lastAmsSendTime >= amsSendInterval)
|
if (currentMillis - lastAmsSendTime >= amsSendInterval)
|
||||||
{
|
{
|
||||||
|
30
src/wlan.cpp
30
src/wlan.cpp
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
WiFiManager wm;
|
WiFiManager wm;
|
||||||
bool wm_nonblocking = false;
|
bool wm_nonblocking = false;
|
||||||
|
uint8_t wifiErrorCounter = 0;
|
||||||
|
|
||||||
void initWiFi() {
|
void initWiFi() {
|
||||||
// Optimierte WiFi-Einstellungen
|
// Optimierte WiFi-Einstellungen
|
||||||
@ -53,3 +54,32 @@ void initWiFi() {
|
|||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkWiFiConnection() {
|
||||||
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
Serial.println("WiFi connection lost. Reconnecting...");
|
||||||
|
oledShowTopRow();
|
||||||
|
oledShowMessage("WiFi reconnecting...");
|
||||||
|
WiFi.reconnect(); // Versuche, die Verbindung wiederherzustellen
|
||||||
|
delay(5000); // Warte 5 Sekunden, bevor erneut geprüft wird
|
||||||
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
Serial.println("Failed to reconnect. Restarting WiFi...");
|
||||||
|
WiFi.disconnect();
|
||||||
|
delay(1000);
|
||||||
|
wifiErrorCounter++;
|
||||||
|
//initWiFi();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wifiErrorCounter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wifiErrorCounter >= 5)
|
||||||
|
{
|
||||||
|
Serial.println("Too many WiFi errors. Restarting...");
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
}
|
@ -4,5 +4,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
void initWiFi();
|
void initWiFi();
|
||||||
|
void checkWiFiConnection();
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user