Revert wifi connectivity stability introduced in 8.1.0.5

Revert wifi connectivity stability introduced in 8.1.0.5 (#7746, #7602, #7621)
This commit is contained in:
Theo Arends 2020-02-20 11:24:35 +01:00
parent 5e4d8e5641
commit 9b1fc4342b
4 changed files with 25 additions and 67 deletions

View File

@ -52,14 +52,12 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
## Changelog ## Changelog
### Version 8.1.0.8 ### Version 8.1.0.9
- Change Lights: simplified gamma correction and 10 bits internal computation - Change Lights: simplified gamma correction and 10 bits internal computation
- Change commands ``Prefix``, ``Ssid``, ``StateText``, ``NTPServer``, and ``FriendlyName`` displaying all items - Change commands ``Prefix``, ``Ssid``, ``StateText``, ``NTPServer``, and ``FriendlyName`` displaying all items
- Change IRremoteESP8266 library updated to v2.7.3 - Change IRremoteESP8266 library updated to v2.7.3
- Change Zigbee command prefix from ``Zigbee*`` to ``Zb*`` - Change Zigbee command prefix from ``Zigbee*`` to ``Zb*``
- Change wifi connectivity stability (#7602)
- Change some wifi code to attempt faster connection (#7621)
- Change MQTT message size with additional 200 characters - Change MQTT message size with additional 200 characters
- Change display of some date and time messages from "Wed Feb 19 10:45:12 2020" to "2020-02-19T10:45:12" - Change display of some date and time messages from "Wed Feb 19 10:45:12 2020" to "2020-02-19T10:45:12"
- Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging - Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging

View File

@ -1,5 +1,9 @@
## Unreleased (development) ## Unreleased (development)
### 8.1.0.9 20200220
- Revert most wifi connectivity changes introduced in 8.1.0.5 (#7746, #7602, #7621)
### 8.1.0.8 20200212 ### 8.1.0.8 20200212
- Change MQTT message size with additional 200 characters - Change MQTT message size with additional 200 characters

View File

@ -22,17 +22,14 @@
\*********************************************************************************************/ \*********************************************************************************************/
#ifndef WIFI_RSSI_THRESHOLD #ifndef WIFI_RSSI_THRESHOLD
// Decrease the roam threshold from 10 to 5 to address devices connecting at very low RSSI and being close to inoperative #define WIFI_RSSI_THRESHOLD 10 // Difference in dB between current network and scanned network
#define WIFI_RSSI_THRESHOLD 5 // Difference in dB between current network and scanned network
#endif #endif
#ifndef WIFI_RESCAN_MINUTES #ifndef WIFI_RESCAN_MINUTES
// Increase rescan interval from 44 to 5 minutes to improve ability for devices to reach network harmony #define WIFI_RESCAN_MINUTES 44 // Number of minutes between wifi network rescan
#define WIFI_RESCAN_MINUTES 5 // Number of minutes between wifi network rescan
#endif #endif
const uint8_t WIFI_CONFIG_SEC = 180; // seconds before restart const uint8_t WIFI_CONFIG_SEC = 180; // seconds before restart
// Drop from 20 seconds to 5 seconds since we control the reconnections, not the Arduino SDK const uint8_t WIFI_CHECK_SEC = 20; // seconds
const uint8_t WIFI_CHECK_SEC = 5; // seconds
const uint8_t WIFI_RETRY_OFFSET_SEC = 20; // seconds const uint8_t WIFI_RETRY_OFFSET_SEC = 20; // seconds
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager #include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
@ -52,8 +49,7 @@ struct WIFI {
uint8_t config_counter = 0; uint8_t config_counter = 0;
uint8_t mdns_begun = 0; // mDNS active uint8_t mdns_begun = 0; // mDNS active
uint8_t scan_state; uint8_t scan_state;
uint8_t bssid[6] = {0}; uint8_t bssid[6];
uint8_t bssid_last[6] = {0}; // store the last connect bssid
int8_t best_network_db; int8_t best_network_db;
} Wifi; } Wifi;
@ -187,11 +183,7 @@ void WifiBegin(uint8_t flag, uint8_t channel)
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N // if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) { WiFi.setPhyMode(WIFI_PHY_MODE_11N); } // B/G/N
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G // if (WiFi.getPhyMode() != WIFI_PHY_MODE_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G
if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); } if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(true); }
// WiFi.setAutoReconnect(true);
// Handle the reconnection in WifiCheckIp() since the autoreconnect keeps sending deauthentication messages which causes the AP to block traffic as it looks like an DoS attack
// This needs to be explicitly called as "false" otherwise the default is enabled
// WiFi.setAutoReconnect(false); // See #7621
switch (flag) { switch (flag) {
case 0: // AP1 case 0: // AP1
case 1: // AP2 case 1: // AP2
@ -273,12 +265,6 @@ void WifiBeginAfterScan(void)
} }
// Scan done // Scan done
if (5 == Wifi.scan_state) { if (5 == Wifi.scan_state) {
uint32_t number_known = 0; // count the number of known AP's so we can clear the Wifi.bssid_last if there is only one
int32_t channel_max = 0; // No scan result
int8_t ap_max = 3; // AP default if not found
uint8_t bssid_max[6]; // Save last bssid
memcpy((void*) &bssid_max, (void*) &Wifi.bssid, sizeof(bssid_max)); // store the strongest bssid
int32_t channel = 0; // No scan result int32_t channel = 0; // No scan result
int8_t ap = 3; // AP default if not found int8_t ap = 3; // AP default if not found
uint8_t last_bssid[6]; // Save last bssid uint8_t last_bssid[6]; // Save last bssid
@ -302,25 +288,12 @@ void WifiBeginAfterScan(void)
for (j = 0; j < MAX_SSIDS; j++) { for (j = 0; j < MAX_SSIDS; j++) {
if (ssid_scan == SettingsText(SET_STASSID1 + j)) { // SSID match if (ssid_scan == SettingsText(SET_STASSID1 + j)) { // SSID match
known = true; known = true;
number_known++;
if (rssi_scan > Wifi.best_network_db) { // Best network if (rssi_scan > Wifi.best_network_db) { // Best network
if (sec_scan == ENC_TYPE_NONE || SettingsText(SET_STAPWD1 + j)) { // Check for passphrase if not open wlan if (sec_scan == ENC_TYPE_NONE || SettingsText(SET_STAPWD1 + j)) { // Check for passphrase if not open wlan
// store the max values in case there is only one AP and we need to try to reconnect
memcpy((void*) &bssid_max, (void*) bssid_scan, sizeof(bssid_max));
channel_max = chan_scan;
ap_max = j;
// if the bssid is not the same as the last failed attempt, force picking the next strongest AP to prevent getting stuck on a strong RSSI, but poor channel health
for (uint32_t i = 0; i < sizeof(Wifi.bssid_last); i++) {
if (bssid_scan[i] != Wifi.bssid_last[i]) {
Wifi.best_network_db = (int8_t)rssi_scan; Wifi.best_network_db = (int8_t)rssi_scan;
channel = chan_scan; channel = chan_scan;
ap = j; // AP1 or AP2 ap = j; // AP1 or AP2
memcpy((void*) &Wifi.bssid, (void*) bssid_scan, sizeof(Wifi.bssid)); memcpy((void*) &Wifi.bssid, (void*) bssid_scan, sizeof(Wifi.bssid));
// save the last bssid used
memcpy((void*) &Wifi.bssid_last, (void*) bssid_scan, sizeof(Wifi.bssid_last));
break;
}
}
} }
} }
break; break;
@ -340,16 +313,6 @@ void WifiBeginAfterScan(void)
WiFi.scanDelete(); // Clean up Ram WiFi.scanDelete(); // Clean up Ram
delay(0); delay(0);
} }
// reset the last bssid if there is only one AP to allow the reconnect of the same AP on the next cycle
if (number_known == 1) {
// clear the last value
memset((void*) &Wifi.bssid_last, 0, sizeof(Wifi.bssid_last));
memcpy((void*) &Wifi.bssid, (void*) bssid_max, sizeof(Wifi.bssid));
channel = channel_max;
ap = ap_max;
}
Wifi.scan_state = 0; Wifi.scan_state = 0;
// If bssid changed then (re)connect wifi // If bssid changed then (re)connect wifi
for (uint32_t i = 0; i < sizeof(Wifi.bssid); i++) { for (uint32_t i = 0; i < sizeof(Wifi.bssid); i++) {
@ -424,13 +387,15 @@ void WifiCheckIp(void)
#else #else
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) { if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
#endif // LWIP_IPV6=1 #endif // LWIP_IPV6=1
// initialize the last connect bssid since we had a successful connection
memset((void*) &Wifi.bssid_last, 0, sizeof(Wifi.bssid_last));
WifiSetState(1); WifiSetState(1);
Wifi.counter = WIFI_CHECK_SEC; Wifi.counter = WIFI_CHECK_SEC;
Wifi.retry = Wifi.retry_init; Wifi.retry = Wifi.retry_init;
if (Wifi.status != WL_CONNECTED) { if (Wifi.status != WL_CONNECTED) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECTED)); AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECTED));
// AddLog_P(LOG_LEVEL_INFO, PSTR("Wifi: Set IP addresses"));
Settings.ip_address[1] = (uint32_t)WiFi.gatewayIP();
Settings.ip_address[2] = (uint32_t)WiFi.subnetMask();
Settings.ip_address[3] = (uint32_t)WiFi.dnsIP();
} }
Wifi.status = WL_CONNECTED; Wifi.status = WL_CONNECTED;
#ifdef USE_DISCOVERY #ifdef USE_DISCOVERY
@ -448,13 +413,11 @@ void WifiCheckIp(void)
switch (Wifi.status) { switch (Wifi.status) {
case WL_CONNECTED: case WL_CONNECTED:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_NO_IP_ADDRESS)); AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_NO_IP_ADDRESS));
// if poor channel health prevents DHCP broadcast from succeeding, restart the request Wifi.status = 0;
// The code will eventually do a recoonect when the 1/2 interval is hit to try another access point if this remains unsuccessful Wifi.retry = Wifi.retry_init;
wifi_station_dhcpc_start();
break; break;
case WL_NO_SSID_AVAIL: case WL_NO_SSID_AVAIL:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_NOT_REACHED)); AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_NOT_REACHED));
if (WIFI_WAIT == Settings.sta_config) { if (WIFI_WAIT == Settings.sta_config) {
Wifi.retry = Wifi.retry_init; Wifi.retry = Wifi.retry_init;
} else { } else {
@ -465,21 +428,17 @@ void WifiCheckIp(void)
Wifi.retry = 0; Wifi.retry = 0;
} }
} }
break; break;
case WL_CONNECT_FAILED: case WL_CONNECT_FAILED:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_WRONG_PASSWORD)); AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_WRONG_PASSWORD));
if (Wifi.retry > (Wifi.retry_init / 2)) { if (Wifi.retry > (Wifi.retry_init / 2)) {
Wifi.retry = Wifi.retry_init / 2; Wifi.retry = Wifi.retry_init / 2;
} }
else if (Wifi.retry) { else if (Wifi.retry) {
Wifi.retry = 0; Wifi.retry = 0;
} }
break; break;
default: // WL_IDLE_STATUS and WL_DISCONNECTED default: // WL_IDLE_STATUS and WL_DISCONNECTED
// log on the 1/2 or full interval
if (!Wifi.retry || ((Wifi.retry_init / 2) == Wifi.retry)) { if (!Wifi.retry || ((Wifi.retry_init / 2) == Wifi.retry)) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_TIMEOUT)); AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_TIMEOUT));
} else { } else {
@ -491,11 +450,9 @@ void WifiCheckIp(void)
} }
} }
} }
if (Wifi.retry) { if (Wifi.retry) {
if (Settings.flag3.use_wifi_scan) { // SetOption56 - Scan wifi network at restart for configured AP's if (Settings.flag3.use_wifi_scan) { // SetOption56 - Scan wifi network at restart for configured AP's
// check the 1/2 interval as well when rescanning - scan state machine takes 4 seconds if (Wifi.retry_init == Wifi.retry) {
if ((Wifi.retry_init == Wifi.retry) || ((Wifi.retry_init / 2) == Wifi.retry)){
Wifi.scan_state = 1; // Select scanned SSID Wifi.scan_state = 1; // Select scanned SSID
} }
} else { } else {
@ -642,6 +599,7 @@ String WifiGetOutputPower(void)
dtostrfd((float)(Settings.wifi_output_power) / 10, 1, stemp1); dtostrfd((float)(Settings.wifi_output_power) / 10, 1, stemp1);
return String(stemp1); return String(stemp1);
} }
void WifiSetOutputPower(void) void WifiSetOutputPower(void)
{ {
WiFi.setOutputPower((float)(Settings.wifi_output_power) / 10); WiFi.setOutputPower((float)(Settings.wifi_output_power) / 10);
@ -653,9 +611,7 @@ void WifiConnect(void)
WifiSetOutputPower(); WifiSetOutputPower();
WiFi.persistent(false); // Solve possible wifi init errors WiFi.persistent(false); // Solve possible wifi init errors
Wifi.status = 0; Wifi.status = 0;
// lower the rety times now Tasmota control the reconnections, not the Arduino SDK Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2);
// Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2);
Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + (ESP.getChipId() & 0xF);
Wifi.retry = Wifi.retry_init; Wifi.retry = Wifi.retry_init;
Wifi.counter = 1; Wifi.counter = 1;
} }

View File

@ -20,7 +20,7 @@
#ifndef _TASMOTA_VERSION_H_ #ifndef _TASMOTA_VERSION_H_
#define _TASMOTA_VERSION_H_ #define _TASMOTA_VERSION_H_
const uint32_t VERSION = 0x08010008; const uint32_t VERSION = 0x08010009;
// Lowest compatible version // Lowest compatible version
const uint32_t VERSION_COMPATIBLE = 0x07010006; const uint32_t VERSION_COMPATIBLE = 0x07010006;