11constexpr unsigned int kPollIntervalMs = 1000;
12constexpr unsigned int kRestartDelayMs = 1000;
18 const String& config_path)
20 timeout_s_(timeout_s),
21 network_state_(network_state) {
40 ESP_LOGI(__FILENAME__,
"Network is back; cancelling the restart.");
51 ESP_LOGW(__FILENAME__,
"Network down for more than %d s; restarting.",
69 if (!config[
"timeout_s"].is<int>()) {
72 const int timeout_s = config[
"timeout_s"].as<
int>();
81 String schema = R
"json({"type":"object","properties":{"timeout_s":{"title":"Timeout (s)","description":"Restart the device after the network has been down for this long. Choose a value that outlasts an access point reboot (1 to {{max}} seconds).","type":"integer","minimum":1,"maximum":{{max}}}}})json";
virtual bool load() override
Load and populate the object from a persistent storage.
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
Restart the device after a prolonged network outage.
WiFiWatchdogPolicy policy_
static constexpr int kMaxTimeoutS
WiFiWatchdog(std::shared_ptr< ValueProducer< NetworkState > > network_state, int timeout_s, const String &config_path="/System/WiFi Watchdog")
void on_network_state(NetworkState state)
uint32_t timeout_ms() const
virtual bool to_json(JsonObject &root) override
static bool is_valid_timeout_s(int timeout_s)
reactesp::RepeatEvent * poll_event_
reactesp::DelayEvent * restart_event_
virtual bool from_json(const JsonObject &config) override
std::shared_ptr< ValueProducer< NetworkState > > network_state_
void set_link_state(WiFiWatchdogLink link, uint32_t now_ms)
bool restart_due(uint32_t now_ms, uint32_t timeout_ms) const
const String ConfigSchema(const SmartSwitchController &obj)
std::shared_ptr< reactesp::EventLoop > event_loop()
WiFiWatchdogLink wifi_watchdog_link_from_state(WiFiState state)
Map a NetworkState (WiFiState) to the watchdog's view of the link.
WiFiWatchdogLink
Link state as seen by the WiFi watchdog.