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 1/2] 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 2/2] 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