mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-13 11:44:29 +05:00
refactor: fix wifi scan on esp32, connection timeouts changed
This commit is contained in:
@@ -247,11 +247,19 @@ namespace NetworkUtils {
|
|||||||
this->delayCallback(250);
|
this->delayCallback(250);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!this->useDhcp) {
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
WiFi.config(this->staticIp, this->staticGateway, this->staticSubnet, this->staticDns);
|
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||||
}
|
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
|
||||||
|
#endif
|
||||||
|
|
||||||
WiFi.begin(this->staSsid, this->staPassword, this->staChannel);
|
if (!this->useDhcp) {
|
||||||
|
WiFi.begin(this->staSsid, this->staPassword, this->staChannel, nullptr, false);
|
||||||
|
WiFi.config(this->staticIp, this->staticGateway, this->staticSubnet, this->staticDns);
|
||||||
|
WiFi.reconnect();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
WiFi.begin(this->staSsid, this->staPassword, this->staChannel, nullptr, true);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long beginConnectionTime = millis();
|
unsigned long beginConnectionTime = millis();
|
||||||
while (millis() - beginConnectionTime < timeout) {
|
while (millis() - beginConnectionTime < timeout) {
|
||||||
@@ -267,7 +275,16 @@ namespace NetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void disconnect() {
|
void disconnect() {
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
|
WiFi.disconnectAsync(false, true);
|
||||||
|
|
||||||
|
const unsigned long start = millis();
|
||||||
|
while (WiFi.isConnected() && (millis() - start) < 5000) {
|
||||||
|
this->delayCallback(100);
|
||||||
|
}
|
||||||
|
#else
|
||||||
WiFi.disconnect(false, true);
|
WiFi.disconnect(false, true);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -365,10 +382,10 @@ namespace NetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const unsigned int reconnectInterval = 5000;
|
const unsigned int reconnectInterval = 15000;
|
||||||
const unsigned int failedConnectTimeout = 120000;
|
const unsigned int failedConnectTimeout = 185000;
|
||||||
const unsigned int connectionTimeout = 15000;
|
const unsigned int connectionTimeout = 5000;
|
||||||
const unsigned int resetConnectionTimeout = 30000;
|
const unsigned int resetConnectionTimeout = 90000;
|
||||||
|
|
||||||
YieldCallback yieldCallback = []() {
|
YieldCallback yieldCallback = []() {
|
||||||
::yield();
|
::yield();
|
||||||
|
|||||||
@@ -769,7 +769,7 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->webServer->handleClient();
|
//this->webServer->handleClient();
|
||||||
this->webServer->stop();
|
this->webServer->stop();
|
||||||
this->webServerEnabled = false;
|
this->webServerEnabled = false;
|
||||||
this->webServerChangeState = millis();
|
this->webServerChangeState = millis();
|
||||||
@@ -794,7 +794,7 @@ protected:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->dnsServer->processNextRequest();
|
//this->dnsServer->processNextRequest();
|
||||||
this->dnsServer->stop();
|
this->dnsServer->stop();
|
||||||
this->dnsServerEnabled = false;
|
this->dnsServerEnabled = false;
|
||||||
this->dnsServerChangeState = millis();
|
this->dnsServerChangeState = millis();
|
||||||
|
|||||||
Reference in New Issue
Block a user