mirror of
https://github.com/wled/WLED.git
synced 2025-07-17 15:56:31 +00:00
Some fixes
This commit is contained in:
parent
3e2aebcd10
commit
5952edc550
@ -714,7 +714,7 @@ bool WLED::findWiFi(bool doScan) {
|
|||||||
|
|
||||||
if (doScan) WiFi.scanDelete(); // restart scan
|
if (doScan) WiFi.scanDelete(); // restart scan
|
||||||
|
|
||||||
int status = WiFi.scanComplete();
|
int status = WiFi.scanComplete(); // complete scan may take as much as several seconds (usually <3s with not very crowded air)
|
||||||
|
|
||||||
if (status == WIFI_SCAN_FAILED) {
|
if (status == WIFI_SCAN_FAILED) {
|
||||||
DEBUG_PRINTLN(F("WiFi scan started."));
|
DEBUG_PRINTLN(F("WiFi scan started."));
|
||||||
@ -747,6 +747,8 @@ bool WLED::findWiFi(bool doScan) {
|
|||||||
|
|
||||||
void WLED::initConnection()
|
void WLED::initConnection()
|
||||||
{
|
{
|
||||||
|
DEBUG_PRINTLN(F("initConnection() called."));
|
||||||
|
|
||||||
#ifdef WLED_ENABLE_WEBSOCKETS
|
#ifdef WLED_ENABLE_WEBSOCKETS
|
||||||
ws.onEvent(wsEvent);
|
ws.onEvent(wsEvent);
|
||||||
#endif
|
#endif
|
||||||
@ -759,11 +761,13 @@ void WLED::initConnection()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (findWiFi()) WiFi.disconnect(); // close old connections (only if scan completed and found networks)
|
WiFi.disconnect(true); // close old connections
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
WiFi.setPhyMode(force802_3g ? WIFI_PHY_MODE_11G : WIFI_PHY_MODE_11N);
|
WiFi.setPhyMode(force802_3g ? WIFI_PHY_MODE_11G : WIFI_PHY_MODE_11N);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
findWiFi(); // update selectedWiFi, initConnection() is called when scan is finished
|
||||||
|
|
||||||
if (multiWiFi[selectedWiFi].staticIP != 0U && multiWiFi[selectedWiFi].staticGW != 0U) {
|
if (multiWiFi[selectedWiFi].staticIP != 0U && multiWiFi[selectedWiFi].staticGW != 0U) {
|
||||||
WiFi.config(multiWiFi[selectedWiFi].staticIP, multiWiFi[selectedWiFi].staticGW, multiWiFi[selectedWiFi].staticSN, dnsAddress);
|
WiFi.config(multiWiFi[selectedWiFi].staticIP, multiWiFi[selectedWiFi].staticGW, multiWiFi[selectedWiFi].staticSN, dnsAddress);
|
||||||
} else {
|
} else {
|
||||||
@ -893,13 +897,13 @@ void WLED::handleConnection()
|
|||||||
static uint32_t lastHeap = UINT32_MAX;
|
static uint32_t lastHeap = UINT32_MAX;
|
||||||
static unsigned long heapTime = 0;
|
static unsigned long heapTime = 0;
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
const bool wifiConfigured = WLED_WIFI_CONFIGURED;
|
||||||
|
|
||||||
if ((now < 500 && WLED_WIFI_CONFIGURED) || (now < 2000 && (!WLED_WIFI_CONFIGURED || apBehavior == AP_BEHAVIOR_ALWAYS)))
|
if ((wifiConfigured && WiFi.scanComplete() < 0) || (now < 2000 && (!wifiConfigured || apBehavior == AP_BEHAVIOR_ALWAYS)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (lastReconnectAttempt == 0 || forceReconnect) {
|
if (lastReconnectAttempt == 0 || forceReconnect) {
|
||||||
DEBUG_PRINTLN(F("Initial connect or forced reconnect."));
|
DEBUG_PRINTLN(F("Initial connect or forced reconnect."));
|
||||||
findWiFi();
|
|
||||||
initConnection();
|
initConnection();
|
||||||
interfacesInited = false;
|
interfacesInited = false;
|
||||||
forceReconnect = false;
|
forceReconnect = false;
|
||||||
@ -935,7 +939,7 @@ void WLED::handleConnection()
|
|||||||
stacO = stac;
|
stacO = stac;
|
||||||
DEBUG_PRINT(F("Connected AP clients: "));
|
DEBUG_PRINT(F("Connected AP clients: "));
|
||||||
DEBUG_PRINTLN(stac);
|
DEBUG_PRINTLN(stac);
|
||||||
if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { // 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
|
||||||
else
|
else
|
||||||
@ -956,7 +960,7 @@ void WLED::handleConnection()
|
|||||||
sendImprovStateResponse(0x03, true);
|
sendImprovStateResponse(0x03, true);
|
||||||
improvActive = 2;
|
improvActive = 2;
|
||||||
}
|
}
|
||||||
if (now - lastReconnectAttempt > ((stac) ? 300000 : 18000) && WLED_WIFI_CONFIGURED) {
|
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_PRINTLN(F("Last reconnect too old."));
|
||||||
initConnection();
|
initConnection();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user