mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-16 18:12:07 +00:00
Don't disconnect WiFi when we're actively reconnecting (#3026)
WiFiEvents may happen asynchronously
This commit is contained in:
parent
d88baea627
commit
db8f8db8e8
@ -38,7 +38,8 @@ bool APStartupComplete = 0;
|
|||||||
|
|
||||||
unsigned long lastrun_ntp = 0;
|
unsigned long lastrun_ntp = 0;
|
||||||
|
|
||||||
bool needReconnect = true; // If we create our reconnector, run it once at the beginning
|
bool needReconnect = true; // If we create our reconnector, run it once at the beginning
|
||||||
|
bool isReconnecting = false; // If we are currently reconnecting
|
||||||
|
|
||||||
WiFiUDP syslogClient;
|
WiFiUDP syslogClient;
|
||||||
Syslog syslog(syslogClient);
|
Syslog syslog(syslogClient);
|
||||||
@ -115,6 +116,7 @@ static int32_t reconnectWiFi()
|
|||||||
wifiPsw = NULL;
|
wifiPsw = NULL;
|
||||||
|
|
||||||
needReconnect = false;
|
needReconnect = false;
|
||||||
|
isReconnecting = true;
|
||||||
|
|
||||||
// Make sure we clear old connection credentials
|
// Make sure we clear old connection credentials
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
@ -129,6 +131,7 @@ static int32_t reconnectWiFi()
|
|||||||
if (!WiFi.isConnected()) {
|
if (!WiFi.isConnected()) {
|
||||||
WiFi.begin(wifiName, wifiPsw);
|
WiFi.begin(wifiName, wifiPsw);
|
||||||
}
|
}
|
||||||
|
isReconnecting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_NTP
|
#ifndef DISABLE_NTP
|
||||||
@ -277,10 +280,12 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||||
LOG_INFO("Disconnected from WiFi access point\n");
|
LOG_INFO("Disconnected from WiFi access point\n");
|
||||||
WiFi.disconnect(false, true);
|
if (!isReconnecting) {
|
||||||
syslog.disable();
|
WiFi.disconnect(false, true);
|
||||||
needReconnect = true;
|
syslog.disable();
|
||||||
wifiReconnect->setIntervalFromNow(1000);
|
needReconnect = true;
|
||||||
|
wifiReconnect->setIntervalFromNow(1000);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
|
||||||
LOG_INFO("Authentication mode of access point has changed\n");
|
LOG_INFO("Authentication mode of access point has changed\n");
|
||||||
@ -294,10 +299,12 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||||
LOG_INFO("Lost IP address and IP address is reset to 0\n");
|
LOG_INFO("Lost IP address and IP address is reset to 0\n");
|
||||||
WiFi.disconnect(false, true);
|
if (!isReconnecting) {
|
||||||
syslog.disable();
|
WiFi.disconnect(false, true);
|
||||||
needReconnect = true;
|
syslog.disable();
|
||||||
wifiReconnect->setIntervalFromNow(1000);
|
needReconnect = true;
|
||||||
|
wifiReconnect->setIntervalFromNow(1000);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ARDUINO_EVENT_WPS_ER_SUCCESS:
|
case ARDUINO_EVENT_WPS_ER_SUCCESS:
|
||||||
LOG_INFO("WiFi Protected Setup (WPS): succeeded in enrollee mode\n");
|
LOG_INFO("WiFi Protected Setup (WPS): succeeded in enrollee mode\n");
|
||||||
@ -398,4 +405,4 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||||||
uint8_t getWifiDisconnectReason()
|
uint8_t getWifiDisconnectReason()
|
||||||
{
|
{
|
||||||
return wifiDisconnectReason;
|
return wifiDisconnectReason;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user