Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

an option to disable boot-loop mechanism #5063

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion sonoff/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions sonoff/user_config_override_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

*/


Expand Down