From c47307bd5e6f54381034acdc916189d647563a62 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 2 Sep 2021 12:25:53 +0200 Subject: [PATCH] Add optional emergency reset Add optional emergency reset when Rx is connected to Tx at restart --- tasmota/settings.ino | 26 ++++++++++++++++++++++++++ tasmota/support.ino | 1 + tasmota/tasmota.ino | 8 +++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 2795c2653..132e438f2 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -276,6 +276,32 @@ void UpdateQuickPowerCycle(bool update) { #endif // FIRMWARE_MINIMAL } +#ifdef USE_EMERGENCY_RESET +/*********************************************************************************************\ + * Emergency reset if Rx and Tx are tied together +\*********************************************************************************************/ + +void EmergencyReset(void) { + Serial.begin(115200); + Serial.write(0xAA); + Serial.write(0x55); + delay(1); + if (Serial.available() == 2) { + if ((Serial.read() == 0xAA) && (Serial.read() == 0x55)) { + SettingsErase(3); // Reset all settings including QuickPowerCycle flag + + do { // Wait for user to remove Rx Tx jumper and power cycle + Serial.write(0xA5); + delay(1000); // Satisfy SDK + } while (Serial.read() == 0xA5); // Poll for removal of jumper + + ESP_Restart(); // Restart to init default settings + } + } + while (Serial.available()) { Serial.read(); } // Flush input buffer +} +#endif // USE_EMERGENCY_RESET + /*********************************************************************************************\ * Settings services \*********************************************************************************************/ diff --git a/tasmota/support.ino b/tasmota/support.ino index 22ff91854..7b7623301 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -2368,6 +2368,7 @@ bool GetLog(uint32_t req_loglevel, uint32_t* index_p, char** entry_pp, size_t* l } void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_payload = nullptr, const char* log_data_retained = nullptr) { + if (!TasmotaGlobal.enable_logging) { return; } // Store log_data in buffer // To lower heap usage log_data_payload may contain the payload data from MqttPublishPayload() // and log_data_retained may contain optional retained message from MqttPublishPayload() diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index f6c0275d3..980f0b7bf 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -133,7 +133,7 @@ struct { bool pwm_present; // Any PWM channel configured with SetOption15 0 bool i2c_enabled; // I2C configured #ifdef ESP32 - bool i2c_enabled_2; // I2C configured, second controller on ESP32, Wire1 + bool i2c_enabled_2; // I2C configured, second controller on ESP32, Wire1 #endif bool ntp_force_sync; // Force NTP sync bool skip_light_fade; // Temporarily skip light fading @@ -141,6 +141,7 @@ struct { bool module_changed; // Indicate module changed since last restart bool wifi_stay_asleep; // Allow sleep only incase of ESP32 BLE bool no_autoexec; // Disable autoexec + bool enable_logging; // Enable logging StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits) uint8_t spi_enabled; // SPI configured @@ -224,6 +225,10 @@ void setup(void) { RtcPreInit(); SettingsInit(); +#ifdef USE_EMERGENCY_RESET + EmergencyReset(); +#endif // USE_EMERGENCY_RESET + memset(&TasmotaGlobal, 0, sizeof(TasmotaGlobal)); TasmotaGlobal.baudrate = APP_BAUDRATE; TasmotaGlobal.seriallog_timer = SERIALLOG_TIMER; @@ -233,6 +238,7 @@ void setup(void) { TasmotaGlobal.tele_period = 9999; TasmotaGlobal.active_device = 1; TasmotaGlobal.global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues + TasmotaGlobal.enable_logging = 1; RtcRebootLoad(); if (!RtcRebootValid()) {