mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-25 22:20:27 +00:00
Replace blocking delay for wifi reconnect with non-blocking to keep button/display interactivity (#6983)
* Update WiFiAPClient.cpp to replace blocking delay() with non-blocking
* Update WiFiAPClient.cpp - fix extra endif
* Update WiFiAPClient.cpp remove duplicate section
* Update WiFiAPClient.cpp
* Update trunk_annotate_pr.yml
* Update trunk_annotate_pr.yml
* Update trunk_check.yml
* Update trunk_check.yml
* Update trunk_format_pr.yml
* Update trunk_annotate_pr.yml
* Attempted to address comments, and fix my other mess.
Thanks for your patience.
* Revert "Update trunk_annotate_pr.yml"
This reverts commit 7db4ff6444
.
* Last mess cleanups (hopefully)
* Undid trunk.yaml changes
* Trunk format
---------
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Tom Fifield <tom@tomfifield.net>
This commit is contained in:
parent
f71fdef3fd
commit
e9d5e36738
@ -46,6 +46,10 @@ uint8_t wifiDisconnectReason = 0;
|
|||||||
// Stores our hostname
|
// Stores our hostname
|
||||||
char ourHost[16];
|
char ourHost[16];
|
||||||
|
|
||||||
|
// To replace blocking wifi connect delay with a non-blocking sleep
|
||||||
|
static unsigned long wifiReconnectStartMillis = 0;
|
||||||
|
static bool wifiReconnectPending = false;
|
||||||
|
|
||||||
bool APStartupComplete = 0;
|
bool APStartupComplete = 0;
|
||||||
|
|
||||||
unsigned long lastrun_ntp = 0;
|
unsigned long lastrun_ntp = 0;
|
||||||
@ -160,8 +164,16 @@ static int32_t reconnectWiFi()
|
|||||||
#endif
|
#endif
|
||||||
LOG_INFO("Reconnecting to WiFi access point %s", wifiName);
|
LOG_INFO("Reconnecting to WiFi access point %s", wifiName);
|
||||||
|
|
||||||
delay(5000);
|
// Start the non-blocking wait for 5 seconds
|
||||||
|
wifiReconnectStartMillis = millis();
|
||||||
|
wifiReconnectPending = true;
|
||||||
|
// Do not attempt to connect yet, wait for the next invocation
|
||||||
|
return 5000; // Schedule next check soon
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we are ready to proceed with the WiFi connection after the 5s wait
|
||||||
|
if (wifiReconnectPending) {
|
||||||
|
if (millis() - wifiReconnectStartMillis >= 5000) {
|
||||||
if (!WiFi.isConnected()) {
|
if (!WiFi.isConnected()) {
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||||
WiFi.mode(WIFI_MODE_NULL);
|
WiFi.mode(WIFI_MODE_NULL);
|
||||||
@ -171,6 +183,11 @@ static int32_t reconnectWiFi()
|
|||||||
WiFi.begin(wifiName, wifiPsw);
|
WiFi.begin(wifiName, wifiPsw);
|
||||||
}
|
}
|
||||||
isReconnecting = false;
|
isReconnecting = false;
|
||||||
|
wifiReconnectPending = false;
|
||||||
|
} else {
|
||||||
|
// Still waiting for 5s to elapse
|
||||||
|
return 100; // Check again soon
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_NTP
|
#ifndef DISABLE_NTP
|
||||||
@ -193,8 +210,6 @@ static int32_t reconnectWiFi()
|
|||||||
|
|
||||||
if (config.network.wifi_enabled && !WiFi.isConnected()) {
|
if (config.network.wifi_enabled && !WiFi.isConnected()) {
|
||||||
#ifdef ARCH_RP2040 // (ESP32 handles this in WiFiEvent)
|
#ifdef ARCH_RP2040 // (ESP32 handles this in WiFiEvent)
|
||||||
/* If APStartupComplete, but we're not connected, try again.
|
|
||||||
Shouldn't try again before APStartupComplete. */
|
|
||||||
needReconnect = APStartupComplete;
|
needReconnect = APStartupComplete;
|
||||||
#endif
|
#endif
|
||||||
return 1000; // check once per second
|
return 1000; // check once per second
|
||||||
@ -486,4 +501,4 @@ uint8_t getWifiDisconnectReason()
|
|||||||
{
|
{
|
||||||
return wifiDisconnectReason;
|
return wifiDisconnectReason;
|
||||||
}
|
}
|
||||||
#endif
|
#endif // HAS_WIFI
|
Loading…
Reference in New Issue
Block a user