From 3146bcf23aee09a940a7e72c0f266990f1844813 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 25 Feb 2020 16:49:19 +0100 Subject: [PATCH 1/5] Add some wifi debug options --- tasmota/settings.h | 2 +- tasmota/settings.ino | 16 ++------ tasmota/support_wifi.ino | 80 ++++++++++++++++++++++++++++++---------- tasmota/tasmota_post.h | 4 +- 4 files changed, 67 insertions(+), 35 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 7952dd9cf..ec81d5345 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -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; diff --git a/tasmota/settings.ino b/tasmota/settings.ino index c2ddc6607..1563897b0 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -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) diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index dd8d2441c..93dba06a9 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -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(); diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index e27213b5a..448fcc6b2 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -694,11 +694,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 // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) +//#include // Arduino_Esp8266 version information (ARDUINO_ESP8266_RELEASE and ARDUINO_ESP8266_RELEASE_2_3_0) #ifndef ARDUINO_ESP8266_RELEASE #define ARDUINO_ESP8266_RELEASE "STAGE" #endif From ec161d5810fc7cc1ed7b8cdb7fefcd4ca5b1ebf4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 25 Feb 2020 16:52:07 +0100 Subject: [PATCH 2/5] Restore default wifi functionality --- tasmota/support_wifi.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 93dba06a9..8f7de0f96 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -23,7 +23,7 @@ // 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 +//#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 From 78e707e73699a19b741b2178d7053069fa7938ee Mon Sep 17 00:00:00 2001 From: stefanbode Date: Tue, 25 Feb 2020 17:55:45 +0100 Subject: [PATCH 3/5] minor bug fixes and enhancements - fix bug in multi-push from last commit - remove rules execution every second. only at start and stop - enable rules for Shutter#Button - tbd: How to correctly detect a simultaneous button push --- tasmota/xdrv_27_shutter.ino | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index 6f4d711d7..1131a5f70 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -255,6 +255,7 @@ void ShutterInit(void) void ShutterReportPosition(bool always) { Response_P(PSTR("{")); + rules_flag.shutter_moving = 0; for (uint32_t i = 0; i < shutters_present; i++) { //AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Shutter %d: Real Pos: %d"), i+1,Shutter.real_position[i]); uint32_t position = ShutterRealToPercentPosition(Shutter.real_position[i], i); @@ -268,7 +269,6 @@ void ShutterReportPosition(bool always) ResponseJsonEnd(); if (always || (rules_flag.shutter_moving)) { MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER)); - XdrvRulesProcess(); } //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: rules_flag.shutter_moving: %d, moved %d"), rules_flag.shutter_moving, rules_flag.shutter_moved); @@ -299,18 +299,23 @@ void ShutterUpdatePosition(void) int32_t max_freq_change_per_sec = Shutter.max_pwm_frequency*steps_per_second / (Shutter.motordelay[i]>0 ? Shutter.motordelay[i] : 1); int32_t min_runtime_ms = Shutter.pwm_frequency[i]*1000 / max_freq_change_per_sec; int32_t velocity = Shutter.direction[i] == 1 ? 100 : Shutter.close_velocity[i]; - int32_t minstopway = min_runtime_ms * velocity / 100 * Shutter.pwm_frequency[i] / max_frequency * Shutter.direction[i] ; + int32_t minstopway = min_runtime_ms * velocity / 100 * Shutter.pwm_frequency[i] / max_frequency * Shutter.direction[i] ; int32_t next_possible_stop = Shutter.real_position[i] + minstopway ; stop_position_delta =200 * Shutter.pwm_frequency[i]/max_frequency + Shutter.direction[i] * (next_possible_stop - Shutter.target_position[i]); + if (Shutter.time[i] == 1) { + ShutterReportPosition(true); + rules_flag.shutter_moving = 1; + XdrvRulesProcess(); + } //Shutter.accelerator[i] = tmin(tmax(max_freq_change_per_sec*(100-(Shutter.direction[i]*(Shutter.target_position[i]-next_possible_stop) ))/2000 , max_freq_change_per_sec*9/200), max_freq_change_per_sec*11/200); //int32_t act_freq_change = max_freq_change_per_sec/20; AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: time: %d, velocity %d, minstopway %d,cur_freq %d, max_frequency %d, act_freq_change %d, min_runtime_ms %d, act.pos %d, next_stop %d, target: %d"),Shutter.time[i],velocity,minstopway, Shutter.pwm_frequency[i],max_frequency, Shutter.accelerator[i],min_runtime_ms,Shutter.real_position[i], next_possible_stop,Shutter.target_position[i]); - if (Shutter.accelerator[i] < 0 || next_possible_stop * Shutter.direction[i] > Shutter.target_position[i] * Shutter.direction[i] ) { + if (Shutter.accelerator[i] < 0 || next_possible_stop * Shutter.direction[i] > (Shutter.target_position[i]- (100 * Shutter.direction[i])) * Shutter.direction[i] ) { - Shutter.accelerator[i] = - tmin(tmax(max_freq_change_per_sec*(100-(Shutter.direction[i]*(Shutter.target_position[i]-next_possible_stop) ))/2000 , max_freq_change_per_sec*9/200), max_freq_change_per_sec*12/200); + Shutter.accelerator[i] = - tmin(tmax(max_freq_change_per_sec*(100-(Shutter.direction[i]*(Shutter.target_position[i]-next_possible_stop) ))/2000 , max_freq_change_per_sec*9/200), max_freq_change_per_sec*11/200); //AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Ramp down: acc: %d"), Shutter.accelerator[i]); } else if ( Shutter.accelerator[i] > 0 && Shutter.pwm_frequency[i] == max_frequency) { Shutter.accelerator[i] = 0; @@ -348,7 +353,7 @@ void ShutterUpdatePosition(void) } analogWrite(pin[GPIO_PWM1+i], 0); Shutter.real_position[i] = ShutterCounterBasedPosition(i); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT:Real %d, pulsecount %d, start %d"), Shutter.real_position[i],RtcSettings.pulse_counter[i], Shutter.start_position[i]); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Real %d, pulsecount %d, start %d"), Shutter.real_position[i],RtcSettings.pulse_counter[i], Shutter.start_position[i]); if ((1 << (Settings.shutter_startrelay[i]-1)) & power) { ExecuteCommandPower(Settings.shutter_startrelay[i], 0, SRC_SHUTTER); @@ -422,6 +427,8 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos) Shutter.time[i] = 0; Shutter.skip_relay_change = 0; Shutter.direction[i] = direction; + rules_flag.shutter_moving = 1; + rules_flag.shutter_moved = 0; //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: real %d, start %d, counter %d, max_freq %d, dir %d, freq %d"),Shutter.real_position[i], Shutter.start_position[i] ,RtcSettings.pulse_counter[i],Shutter.max_pwm_frequency , Shutter.direction[i] ,Shutter.max_pwm_frequency ); } //AddLog_P2(LOG_LEVEL_INFO, PSTR("SHT: Start shutter: %d from %d to %d in directin %d"), i, Shutter.start_position[i], Shutter.target_position[i], Shutter.direction[i]); @@ -538,6 +545,7 @@ void ShutterButtonHandler(void) Button.press_counter[button_index] = 99; // Remember to discard further action for press & hold within button timings } else { Button.press_counter[button_index] = (Button.window_timer[button_index]) ? Button.press_counter[button_index] +1 : 1; + Button.window_timer[button_index] = loops_per_second / 2; // 0.5 second multi press window } } blinks = 201; @@ -590,15 +598,16 @@ void ShutterButtonHandler(void) // check for simultaneous shutter button press uint32 min_shutterbutton_press_counter = -1; for (uint32_t i = 0; i < MAX_KEYS; i++) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Settings.shutter_button[i] %ld, shutter_index %d, Button.press_counter[i] %d, min_shutterbutton_press_counter %d"), Settings.shutter_button[i], shutter_index, Button.press_counter[i] , min_shutterbutton_press_counter); - if ((Settings.shutter_button[i] & (1<<31)) && ((Settings.shutter_button[i] & 0x03) == shutter_index) && (Button.press_counter[i] < min_shutterbutton_press_counter)) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Settings.shutter_button[i] %ld, shutter_index %d, Button.press_counter[i] %d, min_shutterbutton_press_counter %d, i %d"), Settings.shutter_button[i], shutter_index, Button.press_counter[i] , min_shutterbutton_press_counter, i); + if ((Settings.shutter_button[i] & (1<<31)) && ((Settings.shutter_button[i] & 0x03) == shutter_index) && (i != button_index) && (Button.press_counter[i] < min_shutterbutton_press_counter)) { min_shutterbutton_press_counter = Button.press_counter[i]; + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: min_shutterbutton_press_counter %d"), min_shutterbutton_press_counter); } } if (min_shutterbutton_press_counter == Button.press_counter[button_index]) { // simultaneous shutter button press detected - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT:simultanous presss deteced")); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: simultanous presss deteced")); press_index = Button.press_counter[button_index]; for (uint32_t i = 0; i < MAX_KEYS; i++) if ((Settings.shutter_button[i] & (1<<31)) && ((Settings.shutter_button[i] & 0x03) != shutter_index)) @@ -678,6 +687,7 @@ void ShutterButtonHandler(void) ResponseJsonEnd(); MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER)); XdrvRulesProcess(); + } } From 407334be6b2450bc64ee5b19fecd87ec9f872ab7 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 26 Feb 2020 13:45:46 +0100 Subject: [PATCH 4/5] Clean up wifi connection / disconnection --- tasmota/settings.h | 2 +- tasmota/settings.ino | 4 ++++ tasmota/support_wifi.ino | 22 ++++++++++++++-------- tasmota/xdrv_01_webserver.ino | 4 ++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index ec81d5345..886fe7ccf 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -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 force_sdk_erase : 1; // bit 31 (v8.1.0.9) - SetOption113 - Force erase of SDK wifi calibrate secore on restart + uint32_t spare31 : 1; // bit 31 }; } SysBitfield4; diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 1563897b0..5ebf970d4 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -774,6 +774,10 @@ void SettingsErase(uint8_t type) _sectorEnd = _sectorStart +1; // SDK end of phy area and Core calibration sector (0xxFCFFF) } */ + else { + return; + } + 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 diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 8f7de0f96..c98bdc226 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -21,7 +21,8 @@ * Wifi \*********************************************************************************************/ -// Enable only one of two below debug options +// Enable one of three below options for wifi re-connection debugging +//#define WIFI_FORCE_RF_CAL_ERASE // Erase rf calibration sector on restart only //#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 @@ -34,7 +35,7 @@ const uint8_t WIFI_CONFIG_SEC = 180; // seconds before restart const uint8_t WIFI_CHECK_SEC = 20; // seconds -const uint8_t WIFI_RETRY_OFFSET_SEC = 20; // seconds +const uint8_t WIFI_RETRY_OFFSET_SEC = 12; // seconds #include // Wifi, MQTT, Ota, WifiManager #if LWIP_IPV6 @@ -645,7 +646,7 @@ void WifiConnect(void) WifiSetOutputPower(); WiFi.persistent(false); // Solve possible wifi init errors Wifi.status = 0; - Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + ((ESP.getChipId() & 0xF) * 2); + Wifi.retry_init = WIFI_RETRY_OFFSET_SEC + (ESP.getChipId() & 0xF); // Add extra delay to stop overrun by simultanous re-connects Wifi.retry = Wifi.retry_init; Wifi.counter = 1; @@ -659,29 +660,34 @@ void WifiConnect(void) void WifiShutdown(bool option = false) { // option = false - Legacy disconnect also used by DeepSleep - // option = true - Disconnect with SDK wifi calibrate sector erase + // option = true - Disconnect with SDK wifi calibrate sector erase when WIFI_FORCE_RF_CAL_ERASE enabled delay(100); // Allow time for message xfer - disabled v6.1.0b #ifdef USE_EMULATION UdpDisconnect(); + delay(100); // Flush anything in the network buffers. #endif // USE_EMULATION if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT MqttDisconnect(); + delay(100); // Flush anything in the network buffers. } - if (option && Settings.flag4.force_sdk_erase) { // SetOption113 - Force erase of SDK wifi calibrate sector on restart +#ifdef WIFI_FORCE_RF_CAL_ERASE + if (option) { WiFi.disconnect(false); // Disconnect wifi SettingsErase(4); // Delete SDK wifi config and calibrate data - } else { + } else +#endif // WIFI_FORCE_RF_CAL_ERASE + { // 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 + 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 + WiFi.persistent(false); // Do not use SDK storage of SSID/WPA parameters } delay(100); // Flush anything in the network buffers. } diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 33efee99b..3b408cf66 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1882,6 +1882,7 @@ void HandleOtherConfiguration(void) } #ifdef USE_EMULATION +#if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE) WSContentSend_P(PSTR("

 " D_EMULATION " 

")); // Keep close to Friendlynames so do not use
for (uint32_t i = 0; i < EMUL_MAX; i++) { #ifndef USE_EMULATION_WEMO @@ -1899,6 +1900,7 @@ void HandleOtherConfiguration(void) } } WSContentSend_P(PSTR("

")); +#endif // USE_EMULATION_WEMO || USE_EMULATION_HUE #endif // USE_EMULATION WSContentSend_P(HTTP_FORM_END); @@ -1917,8 +1919,10 @@ void OtherSaveSettings(void) SettingsUpdateText(SET_WEBPWD, (!strlen(tmp)) ? "" : (strchr(tmp,'*')) ? SettingsText(SET_WEBPWD) : tmp); Settings.flag.mqtt_enabled = WebServer->hasArg("b1"); // SetOption3 - Enable MQTT #ifdef USE_EMULATION +#if defined(USE_EMULATION_WEMO) || defined(USE_EMULATION_HUE) WebGetArg("b2", tmp, sizeof(tmp)); Settings.flag2.emulation = (!strlen(tmp)) ? 0 : atoi(tmp); +#endif // USE_EMULATION_WEMO || USE_EMULATION_HUE #endif // USE_EMULATION snprintf_P(message, sizeof(message), PSTR(D_LOG_OTHER D_MQTT_ENABLE " %s, " D_CMND_EMULATION " %d, " D_CMND_FRIENDLYNAME), GetStateText(Settings.flag.mqtt_enabled), Settings.flag2.emulation); From f57a4d217cea3baee93bee60c667545f79cb15c4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 26 Feb 2020 14:39:27 +0100 Subject: [PATCH 5/5] Prepare for PWM Dimmer Prepare for PWM Dimmer (#7791) --- tasmota/settings.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index 886fe7ccf..20000aa9f 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -105,9 +105,9 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t zigbee_use_names : 1; // bit 1 (v8.1.0.4) - SetOption83 - Use FriendlyNames instead of ShortAddresses when possible uint32_t awsiot_shadow : 1; // bit 2 (v8.1.0.5) - SetOption84 - (AWS IoT) publish MQTT state to a device shadow uint32_t device_groups_enabled : 1; // bit 3 (v8.1.0.9) - SetOption85 - Enable Device Groups - uint32_t spare04 : 1; - uint32_t spare05 : 1; - uint32_t spare06 : 1; + uint32_t led_timeout : 1; // bit 4 (v8.1.0.9) - SetOption86 - Turn brightness LED's off 5 seconds after last change + uint32_t powered_off_led : 1; // bit 5 (v8.1.0.9) - SetOption87 - Turn red LED on when powered off + uint32_t remote_device_mode : 1; // bit 6 (v8.1.0.9) - SetOption88 - Buttons control remote devices uint32_t spare07 : 1; uint32_t spare08 : 1; uint32_t spare09 : 1; @@ -465,9 +465,13 @@ struct SYSCFG { uint8_t mqttlog_level; // F01 uint8_t sps30_inuse_hours; // F02 uint8_t hotplug_scan; // F03 - uint8_t reserved1; // F04 - reserved for s-hadinger + uint8_t bri_power_on; // F04 + uint8_t bri_min; // F05 + uint8_t bri_preset_low; // F06 + uint8_t bri_preset_high; // F07 + uint8_t button_devices; // F08 - uint8_t free_f05[199]; // F05 + uint8_t free_f05[195]; // F09 uint32_t device_group_share_in; // FCC - Bitmask of device group items imported uint32_t device_group_share_out; // FD0 - Bitmask of device group items exported