mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 18:54:28 +05:00
fix: set policy manual for wifi 13 ch; change timeouts
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "lwip/etharp.h"
|
#include "lwip/etharp.h"
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <esp_wifi.h>
|
||||||
#endif
|
#endif
|
||||||
#include <NetworkConnection.h>
|
#include <NetworkConnection.h>
|
||||||
|
|
||||||
@@ -144,27 +145,41 @@ namespace Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool resetWifi() {
|
bool resetWifi() {
|
||||||
|
// set policy manual for work 13 ch
|
||||||
|
{
|
||||||
|
wifi_country_t country = {"CN", 1, 13, WIFI_COUNTRY_POLICY_MANUAL};
|
||||||
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
wifi_set_country(&country);
|
||||||
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
|
esp_wifi_set_country(&country);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
WiFi.setAutoConnect(false);
|
WiFi.setAutoConnect(false);
|
||||||
WiFi.setAutoReconnect(false);
|
WiFi.setAutoReconnect(false);
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
WiFi.setSleepMode(WIFI_NONE_SLEEP);
|
||||||
|
|
||||||
/*if (wifi_softap_dhcps_status() == DHCP_STARTED) {
|
|
||||||
wifi_softap_dhcps_stop();
|
|
||||||
}*/
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
WiFi.setSleep(WIFI_PS_NONE);
|
WiFi.setSleep(WIFI_PS_NONE);
|
||||||
#endif
|
#endif
|
||||||
WiFi.softAPdisconnect();
|
|
||||||
|
|
||||||
/*#ifdef ARDUINO_ARCH_ESP8266
|
WiFi.softAPdisconnect();
|
||||||
if (wifi_station_dhcpc_status() == DHCP_STARTED) {
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
wifi_station_dhcpc_stop();
|
/*if (wifi_softap_dhcps_status() == DHCP_STARTED) {
|
||||||
}
|
wifi_softap_dhcps_stop();
|
||||||
#endif*/
|
}*/
|
||||||
|
#endif
|
||||||
|
|
||||||
WiFi.disconnect(false, true);
|
WiFi.disconnect(false, true);
|
||||||
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
/*if (wifi_station_dhcpc_status() == DHCP_STARTED) {
|
||||||
|
wifi_station_dhcpc_stop();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
wifi_station_dhcpc_set_maxtry(5);
|
||||||
|
#endif
|
||||||
|
|
||||||
return WiFi.mode(WIFI_OFF);
|
return WiFi.mode(WIFI_OFF);
|
||||||
}
|
}
|
||||||
@@ -246,6 +261,8 @@ namespace Network {
|
|||||||
if (this->isConnected() && !this->hasStaCredentials()) {
|
if (this->isConnected() && !this->hasStaCredentials()) {
|
||||||
Log.sinfoln(FPSTR(L_NETWORK), F("Reset"));
|
Log.sinfoln(FPSTR(L_NETWORK), F("Reset"));
|
||||||
this->resetWifi();
|
this->resetWifi();
|
||||||
|
Connection::reset();
|
||||||
|
this->delayCallback(200);
|
||||||
|
|
||||||
} else if (this->isConnected() && !this->reconnectFlag) {
|
} else if (this->isConnected() && !this->reconnectFlag) {
|
||||||
if (!this->connected) {
|
if (!this->connected) {
|
||||||
@@ -303,6 +320,8 @@ namespace Network {
|
|||||||
} else if (this->isConnecting() && millis() - this->prevReconnectingTime > this->resetConnectionTimeout) {
|
} else if (this->isConnecting() && millis() - this->prevReconnectingTime > this->resetConnectionTimeout) {
|
||||||
Log.swarningln(FPSTR(L_NETWORK), F("Connection timeout, reset wifi..."));
|
Log.swarningln(FPSTR(L_NETWORK), F("Connection timeout, reset wifi..."));
|
||||||
this->resetWifi();
|
this->resetWifi();
|
||||||
|
Connection::reset();
|
||||||
|
this->delayCallback(200);
|
||||||
|
|
||||||
} 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..."));
|
||||||
@@ -324,9 +343,9 @@ namespace Network {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
const unsigned int reconnectInterval = 5000;
|
const unsigned int reconnectInterval = 5000;
|
||||||
const unsigned int failedConnectTimeout = 30000; // 120000
|
const unsigned int failedConnectTimeout = 120000;
|
||||||
const unsigned int connectionTimeout = 15000;
|
const unsigned int connectionTimeout = 15000;
|
||||||
const unsigned int resetConnectionTimeout = 60000;
|
const unsigned int resetConnectionTimeout = 30000;
|
||||||
|
|
||||||
YieldCallback yieldCallback = []() {
|
YieldCallback yieldCallback = []() {
|
||||||
::yield();
|
::yield();
|
||||||
|
|||||||
Reference in New Issue
Block a user