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)
|
||||||
{
|
{
|
||||||
|
96
src/wlan.cpp
96
src/wlan.cpp
@ -8,48 +8,78 @@
|
|||||||
|
|
||||||
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
|
||||||
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
|
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
|
||||||
WiFi.setSleep(false); // disable sleep mode
|
WiFi.setSleep(false); // disable sleep mode
|
||||||
esp_wifi_set_ps(WIFI_PS_NONE);
|
esp_wifi_set_ps(WIFI_PS_NONE);
|
||||||
|
|
||||||
// Maximale Sendeleistung
|
// Maximale Sendeleistung
|
||||||
WiFi.setTxPower(WIFI_POWER_19_5dBm); // Set maximum transmit power
|
WiFi.setTxPower(WIFI_POWER_19_5dBm); // Set maximum transmit power
|
||||||
|
|
||||||
// Optimiere TCP/IP Stack
|
// Optimiere TCP/IP Stack
|
||||||
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
|
esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N);
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
if(wm_nonblocking) wm.setConfigPortalBlocking(false);
|
if(wm_nonblocking) wm.setConfigPortalBlocking(false);
|
||||||
wm.setConfigPortalTimeout(320); // Portal nach 5min schließen
|
wm.setConfigPortalTimeout(320); // Portal nach 5min schließen
|
||||||
|
|
||||||
|
oledShowTopRow();
|
||||||
|
oledShowMessage("WiFi Setup");
|
||||||
|
|
||||||
|
bool res;
|
||||||
|
// res = wm.autoConnect(); // auto generated AP name from chipid
|
||||||
|
res = wm.autoConnect("FilaMan"); // anonymous ap
|
||||||
|
// res = wm.autoConnect("spoolman","password"); // password protected ap
|
||||||
|
|
||||||
|
if(!res) {
|
||||||
|
Serial.println("Failed to connect or hit timeout");
|
||||||
|
// ESP.restart();
|
||||||
|
oledShowTopRow();
|
||||||
|
oledShowMessage("WiFi not connected Check Portal");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wifiOn = true;
|
||||||
|
|
||||||
|
//if you get here you have connected to the WiFi
|
||||||
|
Serial.println("connected...yeey :)");
|
||||||
|
Serial.print("IP address: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
oledShowTopRow();
|
oledShowTopRow();
|
||||||
oledShowMessage("WiFi Setup");
|
display.display();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool res;
|
void checkWiFiConnection() {
|
||||||
// res = wm.autoConnect(); // auto generated AP name from chipid
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
res = wm.autoConnect("FilaMan"); // anonymous ap
|
{
|
||||||
// res = wm.autoConnect("spoolman","password"); // password protected ap
|
Serial.println("WiFi connection lost. Reconnecting...");
|
||||||
|
oledShowTopRow();
|
||||||
if(!res) {
|
oledShowMessage("WiFi reconnecting...");
|
||||||
Serial.println("Failed to connect or hit timeout");
|
WiFi.reconnect(); // Versuche, die Verbindung wiederherzustellen
|
||||||
// ESP.restart();
|
delay(5000); // Warte 5 Sekunden, bevor erneut geprüft wird
|
||||||
oledShowTopRow();
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
oledShowMessage("WiFi not connected Check Portal");
|
{
|
||||||
|
Serial.println("Failed to reconnect. Restarting WiFi...");
|
||||||
|
WiFi.disconnect();
|
||||||
|
delay(1000);
|
||||||
|
wifiErrorCounter++;
|
||||||
|
//initWiFi();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
wifiOn = true;
|
{
|
||||||
|
wifiErrorCounter = 0;
|
||||||
//if you get here you have connected to the WiFi
|
|
||||||
Serial.println("connected...yeey :)");
|
|
||||||
Serial.print("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
|
|
||||||
oledShowTopRow();
|
|
||||||
display.display();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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