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