Add some wifi debug options

This commit is contained in:
Theo Arends 2020-02-25 16:49:19 +01:00 committed by Paul C Diem
parent b3d918f465
commit 1655c1b3aa
4 changed files with 67 additions and 35 deletions

View File

@ -132,7 +132,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t spare28 : 1;
uint32_t spare29 : 1;
uint32_t spare30 : 1;
uint32_t spare31 : 1;
uint32_t force_sdk_erase : 1; // bit 31 (v8.1.0.9) - SetOption113 - Force erase of SDK wifi calibrate secore on restart
};
} SysBitfield4;

View File

@ -745,6 +745,7 @@ void SettingsErase(uint8_t type)
1 = Erase 16k SDK parameter area near end of flash as seen by SDK (0x0xFCxxx - 0x0xFFFFF) solving possible wifi errors
2 = Erase Tasmota parameter area (0x0xF3xxx - 0x0xFBFFF)
3 = Erase Tasmota and SDK parameter area (0x0F3xxx - 0x0FFFFF)
4 = Erase SDK parameter area used for wifi calibration (0x0FCxxx - 0x0FCFFF)
*/
#ifndef FIRMWARE_MINIMAL
@ -762,16 +763,17 @@ void SettingsErase(uint8_t type)
_sectorStart = SETTINGS_LOCATION - CFG_ROTATES; // Tasmota and SDK parameter area (0x0F3xxx - 0x0FFFFF)
_sectorEnd = ESP.getFlashChipSize() / SPI_FLASH_SEC_SIZE; // Flash size as seen by SDK
}
#ifdef USE_WIFI_SDK_ERASE
else if (4 == type) {
// _sectorStart = (ESP.getFlashChipSize() / SPI_FLASH_SEC_SIZE) - 4; // SDK phy area and Core calibration sector (0x0FC000)
_sectorStart = SETTINGS_LOCATION +1; // SDK phy area and Core calibration sector (0x0FC000)
_sectorEnd = _sectorStart +1; // SDK end of phy area and Core calibration sector (0x0FCFFF)
}
/*
else if (5 == type) {
_sectorStart = (ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE) -4; // SDK phy area and Core calibration sector (0xxFC000)
_sectorEnd = _sectorStart +1; // SDK end of phy area and Core calibration sector (0xxFCFFF)
}
#endif // USE_WIFI_SDK_ERASE
*/
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_ERASE " from 0x%08X to 0x%08X"), _sectorStart * SPI_FLASH_SEC_SIZE, (_sectorEnd * SPI_FLASH_SEC_SIZE) -1);
// EspErase(_sectorStart, _sectorEnd); // Arduino core and SDK - erases flash as seen by SDK
@ -786,16 +788,6 @@ void SettingsSdkErase(void)
delay(1000);
}
#ifdef USE_WIFI_SDK_ERASE
void SettingsSdkWifiErase(void)
{
WiFi.disconnect(false); // Delete SDK wifi config
SettingsErase(4);
SettingsErase(5);
delay(200);
}
#endif // USE_WIFI_SDK_ERASE
/********************************************************************************************/
void SettingsDefault(void)

View File

@ -21,6 +21,10 @@
* Wifi
\*********************************************************************************************/
// Enable only one of two below debug options
//#define WIFI_RF_MODE_RF_CAL // Set RF_MODE to RF_CAL for restart and deepsleep during user_rf_pre_init
#define WIFI_RF_PRE_INIT // Set RF_MODE to RF_CAL for restart, deepsleep and power on during user_rf_pre_init
#ifndef WIFI_RSSI_THRESHOLD
#define WIFI_RSSI_THRESHOLD 10 // Difference in dB between current network and scanned network
#endif
@ -609,6 +613,32 @@ void WifiSetOutputPower(void)
WiFi.setOutputPower((float)(Settings.wifi_output_power) / 10);
}
/*
See Esp.h, core_esp8266_phy.cpp and test_overrides.ino
RF_DEFAULT = 0, // RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
RF_CAL = 1, // RF_CAL after deep-sleep wake up, there will be large current.
RF_NO_CAL = 2, // no RF_CAL after deep-sleep wake up, there will only be small current.
RF_DISABLED = 4 // disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
*/
#ifdef WIFI_RF_MODE_RF_CAL
#ifndef USE_DEEPSLEEP
RF_MODE(RF_CAL);
#endif // USE_DEEPSLEEP
#endif // WIFI_RF_MODE_RF_CAL
#ifdef WIFI_RF_PRE_INIT
bool rf_pre_init_flag = false;
RF_PRE_INIT()
{
#ifndef USE_DEEPSLEEP
system_deep_sleep_set_option(1); // The option is 1 by default.
system_phy_set_rfoption(RF_CAL);
#endif // USE_DEEPSLEEP
system_phy_set_powerup_option(3); // 3: RF initialization will do the whole RF calibration which will take about 200ms; this increases the current consumption.
rf_pre_init_flag = true;
}
#endif // WIFI_RF_PRE_INIT
void WifiConnect(void)
{
WifiSetState(0);
@ -618,37 +648,47 @@ void WifiConnect(void)
Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2);
Wifi.retry = Wifi.retry_init;
Wifi.counter = 1;
#ifdef WIFI_RF_PRE_INIT
if (rf_pre_init_flag) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_WIFI "Pre-init done"));
}
#endif // WIFI_RF_PRE_INIT
}
// Enable from 6.0.0a until 6.1.0a - disabled due to possible cause of bad wifi connect on core 2.3.0
// Re-enabled from 6.3.0.7 with ESP.restart replaced by ESP.reset
void WifiDisconnect(void)
{
#ifdef USE_WIFI_SDK_ERASE // Do not enable with DeepSleep as it will wear out flash
SettingsSdkWifiErase();
#else
// Courtesy of EspEasy
WiFi.persistent(true); // use SDK storage of SSID/WPA parameters
ETS_UART_INTR_DISABLE();
wifi_station_disconnect(); // this will store empty ssid/wpa into sdk storage
ETS_UART_INTR_ENABLE();
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
delay(100); // Flush anything in the network buffers.
#endif // USE_WIFI_SDK_ERASE
}
void WifiShutdown(void)
void WifiShutdown(bool option = false)
{
// option = false - Legacy disconnect also used by DeepSleep
// option = true - Disconnect with SDK wifi calibrate sector erase
delay(100); // Allow time for message xfer - disabled v6.1.0b
#ifdef USE_EMULATION
UdpDisconnect();
#endif // USE_EMULATION
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
MqttDisconnect();
}
WifiDisconnect();
if (option && Settings.flag4.force_sdk_erase) { // SetOption113 - Force erase of SDK wifi calibrate sector on restart
WiFi.disconnect(false); // Disconnect wifi
SettingsErase(4); // Delete SDK wifi config and calibrate data
} else {
// Enable from 6.0.0a until 6.1.0a - disabled due to possible cause of bad wifi connect on core 2.3.0
// Re-enabled from 6.3.0.7 with ESP.restart replaced by ESP.reset
// Courtesy of EspEasy
WiFi.persistent(true); // use SDK storage of SSID/WPA parameters
ETS_UART_INTR_DISABLE();
wifi_station_disconnect(); // this will store empty ssid/wpa into sdk storage
ETS_UART_INTR_ENABLE();
WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters
}
delay(100); // Flush anything in the network buffers.
}
void EspRestart(void)
{
WifiShutdown();
WifiShutdown(true);
CrashDumpClear(); // Clear the stack dump in RTC
// ESP.restart(); // This results in exception 3 on restarts on core 2.3.0
ESP.reset();

View File

@ -708,11 +708,11 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack
#endif
#ifndef MESSZ
//#define MESSZ 1040 // Max number of characters in JSON message string (Hass discovery and nice MQTT_MAX_PACKET_SIZE = 1200)
//#define MESSZ 1040 // Max number of characters in JSON message string (Hass discovery and nice MQTT_MAX_PACKET_SIZE = 1200)
#define MESSZ (MQTT_MAX_PACKET_SIZE -TOPSZ -7) // Max number of characters in JSON message string
#endif
//#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
//#include <core_version.h> // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0)
#ifndef ARDUINO_ESP8266_RELEASE
#define ARDUINO_ESP8266_RELEASE "STAGE"
#endif