diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 83bbb7b6514b..20718b75f3ef 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -187,6 +187,19 @@ #define ENERGY_RESOLUTION 3 // [EnergyRes] Maximum number of decimals (0 - 5) showing energy usage in kWh #define CALC_RESOLUTION 3 // [CalcRes] Maximum number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE + +/* boot-loop mechanism + The objective of this mechanism is to protect against endless-loop of reboots (crash?) in a short time. + In such cases the device will get back to default configuration and disable rules. + + To disable it define BOOT_LOOP_DISABLE + To tune it, BOOT_LOOP_MIN will be taken as the min threshold to start this mechanism. Default is 1 +*/ + +#undef BOOT_LOOP_DISABLE +#define BOOT_LOOP_MIN 1 + + /*********************************************************************************************\ * END OF SECTION 1 * @@ -286,7 +299,7 @@ //#define USE_DS18x20_LEGACY // Optional for more than one DS18x20 sensors with dynamic scan using library OneWire (+1k5 code) #define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code) // #define W1_PARASITE_POWER // If using USE_DS18x20 then optimize for parasite powered sensors -// #define DS18B20_INTERNAL_PULLUP // Use INPUT_PULLUP internal pullup resistors for single DS18B20 +// #define DS18B20_INTERNAL_PULLUP // Use INPUT_PULLUP internal pullup resistors for single DS18B20 // -- I2C sensors --------------------------------- #define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 936f7930e78a..bba84d233e1f 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2134,7 +2134,7 @@ void ArduinoOTAInit(void) snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "Arduino OTA " D_SUCCESSFUL ". " D_RESTARTING)); AddLog(LOG_LEVEL_INFO); EspRestart(); - }); + }); ArduinoOTA.begin(); snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD "Arduino OTA " D_ENABLED " " D_PORT " 8266")); @@ -2442,6 +2442,12 @@ extern "C" { extern struct rst_info resetInfo; } +/* get boot loop minimum threshold */ +static int get_bl_th(int level){ + return (BOOT_LOOP_MIN+level); +} + + void setup(void) { RtcRebootLoad(); @@ -2484,31 +2490,33 @@ void setup(void) Settings.flag2.emulation = 0; #endif // USE_EMULATION +#ifndef BOOT_LOOP_DISABLE // Disable functionality as possible cause of fast restart within BOOT_LOOP_TIME seconds (Exception, WDT or restarts) - if (RtcReboot.fast_reboot_count > 1) { // Restart twice + if (RtcReboot.fast_reboot_count > get_bl_th(1)) { // Restart twice Settings.flag3.user_esp8285_enable = 0; // Disable ESP8285 Generic GPIOs interfering with flash SPI - if (RtcReboot.fast_reboot_count > 2) { // Restart 3 times + if (RtcReboot.fast_reboot_count > get_bl_th(2)) { // Restart 3 times for (uint8_t i = 0; i < MAX_RULE_SETS; i++) { if (bitRead(Settings.rule_stop, i)) { bitWrite(Settings.rule_enabled, i, 0); // Disable rules causing boot loop } } } - if (RtcReboot.fast_reboot_count > 3) { // Restarted 4 times + if (RtcReboot.fast_reboot_count > get_bl_th(3)) { // Restarted 4 times Settings.rule_enabled = 0; // Disable all rules } - if (RtcReboot.fast_reboot_count > 4) { // Restarted 5 times + if (RtcReboot.fast_reboot_count > get_bl_th(4)) { // Restarted 5 times for (uint8_t i = 0; i < sizeof(Settings.my_gp); i++) { Settings.my_gp.io[i] = GPIO_NONE; // Reset user defined GPIO disabling sensors } } - if (RtcReboot.fast_reboot_count > 5) { // Restarted 6 times + if (RtcReboot.fast_reboot_count > get_bl_th(5)) { // Restarted 6 times Settings.module = SONOFF_BASIC; // Reset module to Sonoff Basic // Settings.last_module = SONOFF_BASIC; } snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_LOG_SOME_SETTINGS_RESET " (%d)"), RtcReboot.fast_reboot_count); AddLog(LOG_LEVEL_DEBUG); } +#endif Format(mqtt_client, Settings.mqtt_client, sizeof(mqtt_client)); Format(mqtt_topic, Settings.mqtt_topic, sizeof(mqtt_topic)); diff --git a/sonoff/user_config_override_sample.h b/sonoff/user_config_override_sample.h index 9a48d2d5059d..48dc51152d2e 100644 --- a/sonoff/user_config_override_sample.h +++ b/sonoff/user_config_override_sample.h @@ -87,6 +87,12 @@ Examples : #define WIFI_DNS MY_DNS // If not using DHCP set DNS IP address (might be equal to WIFI_GATEWAY) #endif +#ifdef MY_BOOT_LOOP_CFG +#undef BOOT_LOOP_DISABLE +#undef BOOT_LOOP_MIN +#define BOOT_LOOP_MIN 20 +#endif + */