mirror of
https://github.com/meshtastic/firmware.git
synced 2025-10-28 15:22:55 +00:00
Merge e073e09235 into 13c4c2037d
This commit is contained in:
commit
582b3c39b8
@ -49,6 +49,15 @@ char ourHost[16];
|
|||||||
// To replace blocking wifi connect delay with a non-blocking sleep
|
// To replace blocking wifi connect delay with a non-blocking sleep
|
||||||
static unsigned long wifiReconnectStartMillis = 0;
|
static unsigned long wifiReconnectStartMillis = 0;
|
||||||
static bool wifiReconnectPending = false;
|
static bool wifiReconnectPending = false;
|
||||||
|
static unsigned char wifiConnectAttempts = 0;
|
||||||
|
|
||||||
|
#ifndef MAXWIFICONNECTIONATTEMPTS
|
||||||
|
#define MAXWIFICONNECTIONATTEMPTS 6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WIFIRECONNECTGAP
|
||||||
|
#define WIFIRECONNECTGAP 10000
|
||||||
|
#endif
|
||||||
|
|
||||||
bool APStartupComplete = 0;
|
bool APStartupComplete = 0;
|
||||||
|
|
||||||
@ -170,28 +179,44 @@ static int32_t reconnectWiFi()
|
|||||||
#elif defined(ARCH_RP2040)
|
#elif defined(ARCH_RP2040)
|
||||||
WiFi.disconnect(false);
|
WiFi.disconnect(false);
|
||||||
#endif
|
#endif
|
||||||
LOG_INFO("Reconnecting to WiFi access point %s", wifiName);
|
LOG_INFO("Connecting to WiFi access point %s", wifiName);
|
||||||
|
|
||||||
// Start the non-blocking wait for 5 seconds
|
// Start the non-blocking wait for 5 seconds
|
||||||
wifiReconnectStartMillis = millis();
|
wifiReconnectStartMillis = millis();
|
||||||
wifiReconnectPending = true;
|
wifiReconnectPending = true;
|
||||||
// Do not attempt to connect yet, wait for the next invocation
|
// Do not attempt to connect yet, wait for the next invocation
|
||||||
return 5000; // Schedule next check soon
|
return WIFIRECONNECTGAP; // Schedule next check soon
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we are ready to proceed with the WiFi connection after the 5s wait
|
// Check if we are ready to proceed with the WiFi connection after the 5s wait
|
||||||
if (wifiReconnectPending) {
|
if (wifiReconnectPending) {
|
||||||
if (millis() - wifiReconnectStartMillis >= 5000) {
|
if (millis() - wifiReconnectStartMillis >= WIFIRECONNECTGAP) {
|
||||||
if (!WiFi.isConnected()) {
|
if (!WiFi.isConnected()) {
|
||||||
|
wifiConnectAttempts++;
|
||||||
|
LOG_INFO("Reconnecting to WiFi access point %s, attempt %d", wifiName, wifiConnectAttempts);
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||||
WiFi.mode(WIFI_MODE_NULL);
|
WiFi.mode(WIFI_MODE_NULL);
|
||||||
WiFi.useStaticBuffers(true);
|
WiFi.useStaticBuffers(true);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
#endif
|
#endif
|
||||||
WiFi.begin(wifiName, wifiPsw);
|
WiFi.begin(wifiName, wifiPsw);
|
||||||
|
wifiReconnectStartMillis = millis();
|
||||||
|
if(wifiConnectAttempts < MAXWIFICONNECTIONATTEMPTS){
|
||||||
|
needReconnect = true;
|
||||||
}
|
}
|
||||||
isReconnecting = false;
|
else{
|
||||||
|
needReconnect = false;
|
||||||
wifiReconnectPending = false;
|
wifiReconnectPending = false;
|
||||||
|
LOG_INFO("Maximum connection attempts reached %d", wifiConnectAttempts);
|
||||||
|
LOG_INFO("Unable to connect access point %s", wifiName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
LOG_INFO("WiFi successfully connected to access point %s", wifiName);
|
||||||
|
LOG_INFO("Connection attempts %d", wifiConnectAttempts);
|
||||||
|
wifiReconnectPending = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Still waiting for 5s to elapse
|
// Still waiting for 5s to elapse
|
||||||
return 100; // Check again soon
|
return 100; // Check again soon
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user