mirror of
https://github.com/wled/WLED.git
synced 2025-04-27 08:17:17 +00:00
WiFi reconnect bugfix
- additional debug info
This commit is contained in:
parent
1891cc816f
commit
af410ae2d0
@ -207,6 +207,7 @@ void WiFiEvent(WiFiEvent_t event)
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
DEBUG_PRINTF_P(PSTR("Network event: %d\n"), (int)event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,10 +478,7 @@ void WLED::setup()
|
|||||||
if (strcmp(multiWiFi[0].clientSSID, DEFAULT_CLIENT_SSID) == 0)
|
if (strcmp(multiWiFi[0].clientSSID, DEFAULT_CLIENT_SSID) == 0)
|
||||||
showWelcomePage = true;
|
showWelcomePage = true;
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
#ifdef WLED_USE_ETHERNET
|
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
#endif
|
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA); // enable scanning
|
WiFi.mode(WIFI_STA); // enable scanning
|
||||||
findWiFi(true); // start scanning for available WiFi-s
|
findWiFi(true); // start scanning for available WiFi-s
|
||||||
|
|
||||||
@ -781,7 +778,7 @@ int8_t WLED::findWiFi(bool doScan) {
|
|||||||
|
|
||||||
void WLED::initConnection()
|
void WLED::initConnection()
|
||||||
{
|
{
|
||||||
DEBUG_PRINTLN(F("initConnection() called."));
|
DEBUG_PRINTF_P(PSTR("initConnection() called @ %lus.\n"), millis()/1000);
|
||||||
|
|
||||||
#ifdef WLED_ENABLE_WEBSOCKETS
|
#ifdef WLED_ENABLE_WEBSOCKETS
|
||||||
ws.onEvent(wsEvent);
|
ws.onEvent(wsEvent);
|
||||||
@ -825,9 +822,7 @@ void WLED::initConnection()
|
|||||||
if (WLED_WIFI_CONFIGURED) {
|
if (WLED_WIFI_CONFIGURED) {
|
||||||
showWelcomePage = false;
|
showWelcomePage = false;
|
||||||
|
|
||||||
DEBUG_PRINT(F("Connecting to "));
|
DEBUG_PRINTF_P(PSTR("Connecting to %s...\n"), multiWiFi[selectedWiFi].clientSSID);
|
||||||
DEBUG_PRINT(multiWiFi[selectedWiFi].clientSSID);
|
|
||||||
DEBUG_PRINTLN(F("..."));
|
|
||||||
|
|
||||||
// convert the "serverDescription" into a valid DNS hostname (alphanumeric)
|
// convert the "serverDescription" into a valid DNS hostname (alphanumeric)
|
||||||
char hostname[25];
|
char hostname[25];
|
||||||
@ -926,7 +921,8 @@ void WLED::handleConnection()
|
|||||||
{
|
{
|
||||||
static bool scanDone = true;
|
static bool scanDone = true;
|
||||||
static byte stacO = 0;
|
static byte stacO = 0;
|
||||||
unsigned long now = millis();
|
const unsigned long now = millis();
|
||||||
|
const unsigned long nowS = now/1000;
|
||||||
const bool wifiConfigured = WLED_WIFI_CONFIGURED;
|
const bool wifiConfigured = WLED_WIFI_CONFIGURED;
|
||||||
|
|
||||||
// ignore connection handling if WiFi is configured and scan still running
|
// ignore connection handling if WiFi is configured and scan still running
|
||||||
@ -935,7 +931,7 @@ void WLED::handleConnection()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (lastReconnectAttempt == 0 || forceReconnect) {
|
if (lastReconnectAttempt == 0 || forceReconnect) {
|
||||||
DEBUG_PRINTLN(F("Initial connect or forced reconnect."));
|
DEBUG_PRINTF_P(PSTR("Initial connect or forced reconnect (@ %lus).\n"), nowS);
|
||||||
selectedWiFi = findWiFi(); // find strongest WiFi
|
selectedWiFi = findWiFi(); // find strongest WiFi
|
||||||
initConnection();
|
initConnection();
|
||||||
interfacesInited = false;
|
interfacesInited = false;
|
||||||
@ -955,8 +951,7 @@ void WLED::handleConnection()
|
|||||||
#endif
|
#endif
|
||||||
if (stac != stacO) {
|
if (stac != stacO) {
|
||||||
stacO = stac;
|
stacO = stac;
|
||||||
DEBUG_PRINT(F("Connected AP clients: "));
|
DEBUG_PRINTF_P(PSTR("Connected AP clients: %d\n"), (int)stac);
|
||||||
DEBUG_PRINTLN(stac);
|
|
||||||
if (!WLED_CONNECTED && wifiConfigured) { // trying to connect, but not connected
|
if (!WLED_CONNECTED && wifiConfigured) { // trying to connect, but not connected
|
||||||
if (stac)
|
if (stac)
|
||||||
WiFi.disconnect(); // disable search so that AP can work
|
WiFi.disconnect(); // disable search so that AP can work
|
||||||
@ -979,6 +974,7 @@ void WLED::handleConnection()
|
|||||||
initConnection();
|
initConnection();
|
||||||
interfacesInited = false;
|
interfacesInited = false;
|
||||||
scanDone = true;
|
scanDone = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
//send improv failed 6 seconds after second init attempt (24 sec. after provisioning)
|
//send improv failed 6 seconds after second init attempt (24 sec. after provisioning)
|
||||||
if (improvActive > 2 && now - lastReconnectAttempt > 6000) {
|
if (improvActive > 2 && now - lastReconnectAttempt > 6000) {
|
||||||
@ -987,13 +983,13 @@ void WLED::handleConnection()
|
|||||||
}
|
}
|
||||||
if (now - lastReconnectAttempt > ((stac) ? 300000 : 18000) && wifiConfigured) {
|
if (now - lastReconnectAttempt > ((stac) ? 300000 : 18000) && wifiConfigured) {
|
||||||
if (improvActive == 2) improvActive = 3;
|
if (improvActive == 2) improvActive = 3;
|
||||||
DEBUG_PRINTLN(F("Last reconnect too old."));
|
DEBUG_PRINTF_P(PSTR("Last reconnect (%lus) too old (@ %lus).\n"), lastReconnectAttempt/1000, nowS);
|
||||||
if (++selectedWiFi >= multiWiFi.size()) selectedWiFi = 0; // we couldn't connect, try with another network from the list
|
if (++selectedWiFi >= multiWiFi.size()) selectedWiFi = 0; // we couldn't connect, try with another network from the list
|
||||||
initConnection();
|
initConnection();
|
||||||
}
|
}
|
||||||
if (!apActive && now - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) {
|
if (!apActive && now - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) {
|
||||||
if (!(apBehavior == AP_BEHAVIOR_TEMPORARY && now > WLED_AP_TIMEOUT)) {
|
if (!(apBehavior == AP_BEHAVIOR_TEMPORARY && now > WLED_AP_TIMEOUT)) {
|
||||||
DEBUG_PRINTLN(F("Not connected AP."));
|
DEBUG_PRINTF_P(PSTR("Not connected AP (@ %lus).\n"), nowS);
|
||||||
initAP(); // start AP only within first 5min
|
initAP(); // start AP only within first 5min
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1003,7 +999,7 @@ void WLED::handleConnection()
|
|||||||
dnsServer.stop();
|
dnsServer.stop();
|
||||||
WiFi.softAPdisconnect(true);
|
WiFi.softAPdisconnect(true);
|
||||||
apActive = false;
|
apActive = false;
|
||||||
DEBUG_PRINTLN(F("Temporary AP disabled."));
|
DEBUG_PRINTF_P(PSTR("Temporary AP disabled (@ %lus).\n"), nowS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!interfacesInited) { //newly connected
|
} else if (!interfacesInited) { //newly connected
|
||||||
|
Loading…
x
Reference in New Issue
Block a user