15 static const char *
const TAG =
"safe_mode";
18 ESP_LOGCONFIG(TAG,
"Safe Mode:");
19 ESP_LOGCONFIG(TAG,
" Boot considered successful after %" PRIu32
" seconds",
22 ESP_LOGCONFIG(TAG,
" Remain in safe mode for %" PRIu32
" seconds",
27 if (remaining_restarts) {
28 ESP_LOGW(TAG,
"Last reset occurred too quickly; safe mode will be invoked in %" PRIu32
" restarts",
31 ESP_LOGW(TAG,
"SAFE MODE IS ACTIVE");
41 ESP_LOGI(TAG,
"Boot seems successful; resetting boot loop counter");
51 ESP_LOGI(TAG,
"Device will enter safe mode on next boot");
56 ESP_LOGI(TAG,
"Safe mode pending has been cleared");
66 uint32_t boot_is_good_after) {
76 if (is_manual_safe_mode) {
77 ESP_LOGI(TAG,
"Safe mode invoked manually");
79 ESP_LOGCONFIG(TAG,
"There have been %" PRIu32
" suspected unsuccessful boot attempts", this->safe_mode_rtc_value_);
82 if (this->safe_mode_rtc_value_ >= num_attempts || is_manual_safe_mode) {
85 if (!is_manual_safe_mode) {
86 ESP_LOGE(TAG,
"Boot loop detected. Proceeding to safe mode");
91 ESP_LOGW(TAG,
"Safe mode enable time has elapsed -- restarting");
99 ESP_LOGW(TAG,
"SAFE MODE IS ACTIVE");
106 this->
write_rtc_(this->safe_mode_rtc_value_ + 1);
static const uint32_t ENTER_SAFE_MODE_MAGIC
a magic number to indicate that safe mode should be entered on next boot
void set_safe_mode_pending(const bool &pending)
Set to true if the next startup will enter safe mode.
uint32_t safe_mode_boot_is_good_after_
The amount of time after which the boot is considered successful.
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
uint32_t safe_mode_rtc_value_
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
CallbackManager< void()> safe_mode_callback_
uint32_t safe_mode_start_time_
stores when safe mode was enabled
void setup()
Set up all the registered components. Call this at the end of your setup() function.
bool should_enter_safe_mode(uint8_t num_attempts, uint32_t enable_time, uint32_t boot_is_good_after)
uint32_t IRAM_ATTR HOT millis()
void status_set_error(const char *message="unspecified")
void on_safe_shutdown() override
ESPPreferences * global_preferences
Application App
Global storage of Application pointer - only one Application can exist.
void dump_config() override
float get_setup_priority() const override
bool boot_successful_
set to true after boot is considered successful
uint8_t safe_mode_num_attempts_
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t safe_mode_enable_time_
The time safe mode should remain active for.
Implementation of SPI Controller mode.
bool get_safe_mode_pending()
virtual bool sync()=0
Commit pending writes to flash.
void IRAM_ATTR HOT delay(uint32_t ms)
void write_rtc_(uint32_t val)