Remove wifi protocol auto change (#882)
#575 so as to see if in conjunction with the platform update we get a better stability of wifi
This commit is contained in:
1 parent
ac9e8347ed
commit
c3cdd8f04c
2 files changed
+1
-84
No files matched your search
@@ -185,21 +185,6 @@ const char* certificate CERT_ATTRIBUTE = R"EOF("
|
|||||||
int lowpowermode = DEFAULT_LOW_POWER_MODE;
|
int lowpowermode = DEFAULT_LOW_POWER_MODE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// WIFI mode, uncomment to force a wifi mode, if not uncommented the ESP will connect without a mode forced
|
|
||||||
// if there is a reconnection issue it will try to connect with G mode and if not working with B mode
|
|
||||||
#ifdef ESP32
|
|
||||||
# include "esp_wifi.h"
|
|
||||||
uint8_t wifiProtocol = 0; // default mode, automatic selection
|
|
||||||
//uint8_t wifiProtocol = WIFI_PROTOCOL_11B;
|
|
||||||
//uint8_t wifiProtocol = WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G; // can't have only one https://github.com/espressif/esp-idf/issues/702
|
|
||||||
//uint8_t wifiProtocol = WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N; // can't have only one https://github.com/espressif/esp-idf/issues/702
|
|
||||||
#elif ESP8266
|
|
||||||
uint8_t wifiProtocol = 0; // default mode, automatic selection
|
|
||||||
//uint8_t wifiProtocol = WIFI_PHY_MODE_11B;
|
|
||||||
//uint8_t wifiProtocol = WIFI_PHY_MODE_11G;
|
|
||||||
//uint8_t wifiProtocol = WIFI_PHY_MODE_11N;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
|
/*-------------DEFINE THE MODULES YOU WANT BELOW----------------*/
|
||||||
//Addons and module management, uncomment the Z line corresponding to the module you want to use
|
//Addons and module management, uncomment the Z line corresponding to the module you want to use
|
||||||
|
|
||||||
|
|||||||
+1
-69
@@ -168,7 +168,6 @@ unsigned long timer_led_measures = 0;
|
|||||||
# include <ArduinoOTA.h>
|
# include <ArduinoOTA.h>
|
||||||
# include <FS.h>
|
# include <FS.h>
|
||||||
# include <SPIFFS.h>
|
# include <SPIFFS.h>
|
||||||
# include <esp_wifi.h>
|
|
||||||
|
|
||||||
# ifdef ESP32_ETHERNET
|
# ifdef ESP32_ETHERNET
|
||||||
# define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
|
# define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
|
||||||
@@ -510,9 +509,6 @@ void connectMQTT() {
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
digitalWrite(LED_INFO, !LED_INFO_ON);
|
digitalWrite(LED_INFO, !LED_INFO_ON);
|
||||||
delay(4000);
|
delay(4000);
|
||||||
#if defined(ESP8266) || defined(ESP32) && !defined(ESP32_ETHERNET)
|
|
||||||
disconnection_handling(failure_number_mqtt);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,7 +564,6 @@ void setup() {
|
|||||||
# else
|
# else
|
||||||
setup_wifimanager(false);
|
setup_wifimanager(false);
|
||||||
# endif
|
# endif
|
||||||
Log.trace(F("OpenMQTTGateway Wifi protocol used: %d" CR), wifiProtocol);
|
|
||||||
Log.trace(F("OpenMQTTGateway mac: %s" CR), WiFi.macAddress().c_str());
|
Log.trace(F("OpenMQTTGateway mac: %s" CR), WiFi.macAddress().c_str());
|
||||||
Log.trace(F("OpenMQTTGateway ip: %s" CR), WiFi.localIP().toString().c_str());
|
Log.trace(F("OpenMQTTGateway ip: %s" CR), WiFi.localIP().toString().c_str());
|
||||||
# endif
|
# endif
|
||||||
@@ -750,64 +745,6 @@ bool wifi_reconnect_bypass() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the 2 methods below are used to recover wifi connection by changing the protocols
|
|
||||||
void forceWifiProtocol() {
|
|
||||||
# ifdef ESP32
|
|
||||||
Log.warning(F("ESP32: Forcing to wifi %d" CR), wifiProtocol);
|
|
||||||
esp_wifi_set_protocol(WIFI_IF_STA, wifiProtocol);
|
|
||||||
# elif ESP8266
|
|
||||||
Log.warning(F("ESP8266: Forcing to wifi %d" CR), wifiProtocol);
|
|
||||||
WiFi.setPhyMode((WiFiPhyMode_t)wifiProtocol);
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void reinit_wifi() {
|
|
||||||
delay(10);
|
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
if (wifiProtocol) forceWifiProtocol();
|
|
||||||
WiFi.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void disconnection_handling(int failure_number) {
|
|
||||||
Log.warning(F("disconnection_handling, failed %d times" CR), failure_number);
|
|
||||||
if ((failure_number > maxConnectionRetry) && !connectedOnce) {
|
|
||||||
# ifndef ESPWifiManualSetup
|
|
||||||
Log.error(F("Failed connecting 1st time to mqtt, you should put TRIGGER_GPIO to LOW or erase the flash" CR));
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
if (failure_number <= (maxConnectionRetry + ATTEMPTS_BEFORE_BG)) {
|
|
||||||
Log.warning(F("Attempt to reinit wifi: %d" CR), wifiProtocol);
|
|
||||||
reinit_wifi();
|
|
||||||
} else if ((failure_number > (maxConnectionRetry + ATTEMPTS_BEFORE_BG)) && (failure_number <= (maxConnectionRetry + ATTEMPTS_BEFORE_B))) // After maxConnectionRetry + ATTEMPTS_BEFORE_BG try to connect with BG protocol
|
|
||||||
{
|
|
||||||
# ifdef ESP32
|
|
||||||
wifiProtocol = WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G;
|
|
||||||
# elif ESP8266
|
|
||||||
wifiProtocol = WIFI_PHY_MODE_11G;
|
|
||||||
# endif
|
|
||||||
Log.warning(F("Wifi Protocol changed to WIFI_11G: %d" CR), wifiProtocol);
|
|
||||||
reinit_wifi();
|
|
||||||
} else if ((failure_number > (maxConnectionRetry + ATTEMPTS_BEFORE_B)) && (failure_number <= (maxConnectionRetry + ATTEMPTS_BEFORE_B + ATTEMPTS_BEFORE_BG))) // After maxConnectionRetry + ATTEMPTS_BEFORE_B try to connect with B protocol
|
|
||||||
{
|
|
||||||
# ifdef ESP32
|
|
||||||
wifiProtocol = WIFI_PROTOCOL_11B;
|
|
||||||
# elif ESP8266
|
|
||||||
wifiProtocol = WIFI_PHY_MODE_11B;
|
|
||||||
# endif
|
|
||||||
Log.warning(F("Wifi Protocol changed to WIFI_11B: %d" CR), wifiProtocol);
|
|
||||||
reinit_wifi();
|
|
||||||
} else if (failure_number > (maxConnectionRetry + ATTEMPTS_BEFORE_B + ATTEMPTS_BEFORE_BG)) // After maxConnectionRetry + ATTEMPTS_BEFORE_B try to connect with B protocol
|
|
||||||
{
|
|
||||||
# ifdef ESP32
|
|
||||||
wifiProtocol = 0;
|
|
||||||
# elif ESP8266
|
|
||||||
wifiProtocol = 0;
|
|
||||||
# endif
|
|
||||||
Log.warning(F("Wifi Protocol reverted to normal mode: %d" CR), wifiProtocol);
|
|
||||||
reinit_wifi();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setOTA() {
|
void setOTA() {
|
||||||
// Port defaults to 8266
|
// Port defaults to 8266
|
||||||
ArduinoOTA.setPort(ota_port);
|
ArduinoOTA.setPort(ota_port);
|
||||||
@@ -879,7 +816,6 @@ void setup_wifi() {
|
|||||||
char manual_wifi_password[] = wifi_password;
|
char manual_wifi_password[] = wifi_password;
|
||||||
delay(10);
|
delay(10);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
if (wifiProtocol) forceWifiProtocol();
|
|
||||||
|
|
||||||
// We start by connecting to a WiFi network
|
// We start by connecting to a WiFi network
|
||||||
Log.trace(F("Connecting to %s" CR), manual_wifi_ssid);
|
Log.trace(F("Connecting to %s" CR), manual_wifi_ssid);
|
||||||
@@ -900,7 +836,6 @@ void setup_wifi() {
|
|||||||
delay(500);
|
delay(500);
|
||||||
Log.trace(F("." CR));
|
Log.trace(F("." CR));
|
||||||
failure_number_ntwk++;
|
failure_number_ntwk++;
|
||||||
disconnection_handling(failure_number_ntwk);
|
|
||||||
# if defined(ESP32) && defined(ZgatewayBT)
|
# if defined(ESP32) && defined(ZgatewayBT)
|
||||||
if (failure_number_ntwk > maxConnectionRetryWifi)
|
if (failure_number_ntwk > maxConnectionRetryWifi)
|
||||||
lowPowerESP32();
|
lowPowerESP32();
|
||||||
@@ -969,7 +904,6 @@ void setup_wifimanager(bool reset_settings) {
|
|||||||
# endif
|
# endif
|
||||||
delay(10);
|
delay(10);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
if (wifiProtocol) forceWifiProtocol();
|
|
||||||
|
|
||||||
if (reset_settings)
|
if (reset_settings)
|
||||||
eraseAndRestart();
|
eraseAndRestart();
|
||||||
@@ -1370,9 +1304,8 @@ void loop() {
|
|||||||
digitalWrite(LED_INFO, !LED_INFO_ON);
|
digitalWrite(LED_INFO, !LED_INFO_ON);
|
||||||
delay(5000);
|
delay(5000);
|
||||||
#if defined(ESP8266) || defined(ESP32) && !defined(ESP32_ETHERNET)
|
#if defined(ESP8266) || defined(ESP32) && !defined(ESP32_ETHERNET)
|
||||||
|
WiFi.reconnect();
|
||||||
Log.warning(F("wifi" CR));
|
Log.warning(F("wifi" CR));
|
||||||
failure_number_ntwk++;
|
|
||||||
disconnection_handling(failure_number_ntwk);
|
|
||||||
#else
|
#else
|
||||||
Log.warning(F("ethernet" CR));
|
Log.warning(F("ethernet" CR));
|
||||||
#endif
|
#endif
|
||||||
@@ -1411,7 +1344,6 @@ void stateMeasures() {
|
|||||||
SYSdata["ip"] = ip2CharArray(WiFi.localIP());
|
SYSdata["ip"] = ip2CharArray(WiFi.localIP());
|
||||||
String mac = WiFi.macAddress();
|
String mac = WiFi.macAddress();
|
||||||
SYSdata["mac"] = (char*)mac.c_str();
|
SYSdata["mac"] = (char*)mac.c_str();
|
||||||
SYSdata["wifiprt"] = (int)wifiProtocol;
|
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# ifdef ZgatewayBT
|
# ifdef ZgatewayBT
|
||||||
|
|||||||
Reference in new issue
Block a user