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
### Version 8.1.0.8
### Version 8.1.0.9
- Change Lights: simplified gamma correction and 10 bits internal computation
- Change commands ``Prefix``, ``Ssid``, ``StateText``, ``NTPServer``, and ``FriendlyName`` displaying all items
- Change IRremoteESP8266 library updated to v2.7.3
- 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 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

View File

@ -1,5 +1,9 @@
## 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
- Change MQTT message size with additional 200 characters

View File

@ -22,17 +22,14 @@
\*********************************************************************************************/
#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 5 // Difference in dB between current network and scanned network
#define WIFI_RSSI_THRESHOLD 10 // Difference in dB between current network and scanned network
#endif
#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 5 // Number of minutes between wifi network rescan
#define WIFI_RESCAN_MINUTES 44 // Number of minutes between wifi network rescan
#endif
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 = 5; // seconds
const uint8_t WIFI_CHECK_SEC = 20; // seconds
const uint8_t WIFI_RETRY_OFFSET_SEC = 20; // seconds
#include <ESP8266WiFi.h> // Wifi, MQTT, Ota, WifiManager
@ -52,8 +49,7 @@ struct WIFI {
uint8_t config_counter = 0;
uint8_t mdns_begun = 0; // mDNS active
uint8_t scan_state;
uint8_t bssid[6] = {0};
uint8_t bssid_last[6] = {0}; // store the last connect bssid
uint8_t bssid[6];
int8_t best_network_db;
} 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_11G) { WiFi.setPhyMode(WIFI_PHY_MODE_11G); } // B/G
if (!WiFi.getAutoConnect()) { WiFi.setAutoConnect(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
// WiFi.setAutoReconnect(true);
switch (flag) {
case 0: // AP1
case 1: // AP2
@ -249,7 +241,7 @@ void WifiBeginAfterScan(void)
if (2 == Wifi.scan_state) {
uint8_t* bssid = WiFi.BSSID(); // Get current bssid
memcpy((void*) &Wifi.bssid, (void*) bssid, sizeof(Wifi.bssid));
Wifi.best_network_db = WiFi.RSSI(); // Get current rssi and add threshold
Wifi.best_network_db = WiFi.RSSI(); // Get current rssi and add threshold
if (Wifi.best_network_db < -WIFI_RSSI_THRESHOLD) {
Wifi.best_network_db += WIFI_RSSI_THRESHOLD;
}
@ -273,12 +265,6 @@ void WifiBeginAfterScan(void)
}
// Scan done
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
int8_t ap = 3; // AP default if not found
uint8_t last_bssid[6]; // Save last bssid
@ -302,25 +288,12 @@ void WifiBeginAfterScan(void)
for (j = 0; j < MAX_SSIDS; j++) {
if (ssid_scan == SettingsText(SET_STASSID1 + j)) { // SSID match
known = true;
number_known++;
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
// 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;
channel = chan_scan;
ap = j; // AP1 or AP2
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;
}
}
Wifi.best_network_db = (int8_t)rssi_scan;
channel = chan_scan;
ap = j; // AP1 or AP2
memcpy((void*) &Wifi.bssid, (void*) bssid_scan, sizeof(Wifi.bssid));
}
}
break;
@ -340,16 +313,6 @@ void WifiBeginAfterScan(void)
WiFi.scanDelete(); // Clean up Ram
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;
// If bssid changed then (re)connect wifi
for (uint32_t i = 0; i < sizeof(Wifi.bssid); i++) {
@ -424,13 +387,15 @@ void WifiCheckIp(void)
#else
if ((WL_CONNECTED == WiFi.status()) && (static_cast<uint32_t>(WiFi.localIP()) != 0)) {
#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);
Wifi.counter = WIFI_CHECK_SEC;
Wifi.retry = Wifi.retry_init;
if (Wifi.status != WL_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;
#ifdef USE_DISCOVERY
@ -448,13 +413,11 @@ void WifiCheckIp(void)
switch (Wifi.status) {
case WL_CONNECTED:
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
// The code will eventually do a recoonect when the 1/2 interval is hit to try another access point if this remains unsuccessful
wifi_station_dhcpc_start();
Wifi.status = 0;
Wifi.retry = Wifi.retry_init;
break;
case WL_NO_SSID_AVAIL:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_NOT_REACHED));
if (WIFI_WAIT == Settings.sta_config) {
Wifi.retry = Wifi.retry_init;
} else {
@ -465,21 +428,17 @@ void WifiCheckIp(void)
Wifi.retry = 0;
}
}
break;
case WL_CONNECT_FAILED:
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_WRONG_PASSWORD));
if (Wifi.retry > (Wifi.retry_init / 2)) {
Wifi.retry = Wifi.retry_init / 2;
}
else if (Wifi.retry) {
Wifi.retry = 0;
}
break;
default: // WL_IDLE_STATUS and WL_DISCONNECTED
// log on the 1/2 or full interval
if (!Wifi.retry || ((Wifi.retry_init / 2) == Wifi.retry)) {
AddLog_P(LOG_LEVEL_INFO, S_LOG_WIFI, PSTR(D_CONNECT_FAILED_AP_TIMEOUT));
} else {
@ -491,11 +450,9 @@ void WifiCheckIp(void)
}
}
}
if (Wifi.retry) {
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) || ((Wifi.retry_init / 2) == Wifi.retry)){
if (Wifi.retry_init == Wifi.retry) {
Wifi.scan_state = 1; // Select scanned SSID
}
} else {
@ -642,6 +599,7 @@ String WifiGetOutputPower(void)
dtostrfd((float)(Settings.wifi_output_power) / 10, 1, stemp1);
return String(stemp1);
}
void WifiSetOutputPower(void)
{
WiFi.setOutputPower((float)(Settings.wifi_output_power) / 10);
@ -653,9 +611,7 @@ void WifiConnect(void)
WifiSetOutputPower();
WiFi.persistent(false); // Solve possible wifi init errors
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);
Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2);
Wifi.retry = Wifi.retry_init;
Wifi.counter = 1;
}

View File

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