mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +05:00
refactor: NetworkMgr code optimization
This commit is contained in:
@@ -203,6 +203,7 @@ namespace NetworkUtils {
|
|||||||
|
|
||||||
if (force && !this->isApEnabled()) {
|
if (force && !this->isApEnabled()) {
|
||||||
this->resetWifi();
|
this->resetWifi();
|
||||||
|
NetworkConnection::reset();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/*#ifdef ARDUINO_ARCH_ESP8266
|
/*#ifdef ARDUINO_ARCH_ESP8266
|
||||||
@@ -218,7 +219,7 @@ namespace NetworkUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->delayCallback(200);
|
this->delayCallback(250);
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
if (this->setWifiHostname(this->hostname)) {
|
if (this->setWifiHostname(this->hostname)) {
|
||||||
@@ -233,7 +234,7 @@ namespace NetworkUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->delayCallback(200);
|
this->delayCallback(250);
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
if (this->setWifiHostname(this->hostname)) {
|
if (this->setWifiHostname(this->hostname)) {
|
||||||
@@ -243,7 +244,7 @@ namespace NetworkUtils {
|
|||||||
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->hostname);
|
Log.serrorln(FPSTR(L_NETWORK), F("Set hostname '%s': fail"), this->hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->delayCallback(200);
|
this->delayCallback(250);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!this->useDhcp) {
|
if (!this->useDhcp) {
|
||||||
@@ -266,13 +267,22 @@ namespace NetworkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (this->isConnected() && !this->hasStaCredentials()) {
|
if (this->reconnectFlag) {
|
||||||
|
this->delayCallback(5000);
|
||||||
|
|
||||||
|
Log.sinfoln(FPSTR(L_NETWORK), F("Reconnecting..."));
|
||||||
|
this->reconnectFlag = false;
|
||||||
|
this->resetWifi();
|
||||||
|
NetworkConnection::reset();
|
||||||
|
this->delayCallback(1000);
|
||||||
|
|
||||||
|
} else if (this->isConnected() && !this->hasStaCredentials()) {
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("Reset"));
|
Log.sinfoln(FPSTR(L_NETWORK), F("Reset"));
|
||||||
this->resetWifi();
|
this->resetWifi();
|
||||||
NetworkConnection::reset();
|
NetworkConnection::reset();
|
||||||
this->delayCallback(200);
|
this->delayCallback(1000);
|
||||||
|
|
||||||
} else if (this->isConnected() && !this->reconnectFlag) {
|
} else if (this->isConnected()) {
|
||||||
if (!this->connected) {
|
if (!this->connected) {
|
||||||
this->connectedTime = millis();
|
this->connectedTime = millis();
|
||||||
this->connected = true;
|
this->connected = true;
|
||||||
@@ -331,12 +341,11 @@ namespace NetworkUtils {
|
|||||||
Log.swarningln(FPSTR(L_NETWORK), F("Connection timeout, reset wifi..."));
|
Log.swarningln(FPSTR(L_NETWORK), F("Connection timeout, reset wifi..."));
|
||||||
this->resetWifi();
|
this->resetWifi();
|
||||||
NetworkConnection::reset();
|
NetworkConnection::reset();
|
||||||
this->delayCallback(200);
|
this->delayCallback(250);
|
||||||
|
|
||||||
} else if (!this->isConnecting() && this->hasStaCredentials() && (!this->prevReconnectingTime || millis() - this->prevReconnectingTime > this->reconnectInterval)) {
|
} else if (!this->isConnecting() && this->hasStaCredentials() && (!this->prevReconnectingTime || millis() - this->prevReconnectingTime > this->reconnectInterval)) {
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("Try connect..."));
|
Log.sinfoln(FPSTR(L_NETWORK), F("Try connect..."));
|
||||||
|
|
||||||
this->reconnectFlag = false;
|
|
||||||
NetworkConnection::reset();
|
NetworkConnection::reset();
|
||||||
if (!this->connect(true, this->connectionTimeout)) {
|
if (!this->connect(true, this->connectionTimeout)) {
|
||||||
Log.straceln(FPSTR(L_NETWORK), F("Connection failed. Status: %d, reason: %d"), NetworkConnection::getStatus(), NetworkConnection::getDisconnectReason());
|
Log.straceln(FPSTR(L_NETWORK), F("Connection failed. Status: %d, reason: %d"), NetworkConnection::getStatus(), NetworkConnection::getDisconnectReason());
|
||||||
|
|||||||
Reference in New Issue
Block a user