SensESP 3.6.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::WiFiWatchdog Class Reference

Restart the device after a prolonged network outage. More...

#include <sensesp/system/wifi_watchdog.h>

Inheritance diagram for sensesp::WiFiWatchdog:
[legend]

Public Member Functions

 WiFiWatchdog (std::shared_ptr< ValueProducer< NetworkState > > network_state, int timeout_s, const String &config_path="/System/WiFi Watchdog")
 
virtual ~WiFiWatchdog ()
 
virtual bool to_json (JsonObject &root) override
 
virtual bool from_json (const JsonObject &config) override
 
- Public Member Functions inherited from sensesp::FileSystemSaveable
 FileSystemSaveable (const String &config_path)
 
virtual bool load () override
 Load and populate the object from a persistent storage.
 
virtual bool save () override
 Save the object to a persistent storage.
 
virtual bool clear () override
 Delete the data from a persistent storage.
 
bool find_config_file (const String &config_path, String &filename)
 
- Public Member Functions inherited from sensesp::Saveable
 Saveable (const String &config_path)
 
virtual bool refresh ()
 Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state.
 
const String & get_config_path () const
 

Static Public Member Functions

static bool is_valid_timeout_s (int timeout_s)
 

Static Public Attributes

static constexpr int kMaxTimeoutS = 7 * 24 * 3600
 

Protected Member Functions

void on_network_state (NetworkState state)
 
void poll ()
 
uint32_t timeout_ms () const
 

Protected Attributes

int timeout_s_
 
std::shared_ptr< ValueProducer< NetworkState > > network_state_
 
int state_observer_id_ = -1
 
reactesp::RepeatEvent * poll_event_ = nullptr
 
reactesp::DelayEvent * restart_event_ = nullptr
 
WiFiWatchdogPolicy policy_
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 

Detailed Description

Restart the device after a prolonged network outage.

Consumes NetworkState from the app's NetworkStateProducer and polls a WiFiWatchdogPolicy once a second. The watchdog arms on the first station or Ethernet connection after boot, so a device that starts without a reachable access point is left running. The soft-AP and the captive portal neither arm the watchdog nor count as an outage. Once armed, a continuous outage of at least the configured timeout restarts the device.

The timeout is persisted under the config path and editable from the web UI. It is read on every poll, so a change takes effect without a restart. A persisted value takes precedence over the constructor argument on later boots.

Parameters
network_stateProducer of the link state to watch.
timeout_sInitial outage duration in seconds before restarting. Must satisfy is_valid_timeout_s(); the caller validates.
config_pathPath under which the timeout is persisted and shown in the web UI.

Definition at line 37 of file wifi_watchdog.h.

Constructor & Destructor Documentation

◆ WiFiWatchdog()

sensesp::WiFiWatchdog::WiFiWatchdog ( std::shared_ptr< ValueProducer< NetworkState > >  network_state,
int  timeout_s,
const String &  config_path = "/System/WiFi Watchdog" 
)

Definition at line 16 of file wifi_watchdog.cpp.

Here is the call graph for this function:

◆ ~WiFiWatchdog()

sensesp::WiFiWatchdog::~WiFiWatchdog ( )
virtual

Definition at line 28 of file wifi_watchdog.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ from_json()

bool sensesp::WiFiWatchdog::from_json ( const JsonObject &  root)
overridevirtual

Deserializes the current object data from a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 68 of file wifi_watchdog.cpp.

Here is the call graph for this function:

◆ is_valid_timeout_s()

static bool sensesp::WiFiWatchdog::is_valid_timeout_s ( int  timeout_s)
inlinestatic

Definition at line 42 of file wifi_watchdog.h.

Here is the caller graph for this function:

◆ on_network_state()

void sensesp::WiFiWatchdog::on_network_state ( NetworkState  state)
protected

Definition at line 36 of file wifi_watchdog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ poll()

void sensesp::WiFiWatchdog::poll ( )
protected

Definition at line 46 of file wifi_watchdog.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeout_ms()

uint32_t sensesp::WiFiWatchdog::timeout_ms ( ) const
inlineprotected

Definition at line 57 of file wifi_watchdog.h.

Here is the caller graph for this function:

◆ to_json()

bool sensesp::WiFiWatchdog::to_json ( JsonObject &  root)
overridevirtual

Serializes the current object data into a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 63 of file wifi_watchdog.cpp.

Member Data Documentation

◆ kMaxTimeoutS

constexpr int sensesp::WiFiWatchdog::kMaxTimeoutS = 7 * 24 * 3600
staticconstexpr

Definition at line 40 of file wifi_watchdog.h.

◆ network_state_

std::shared_ptr<ValueProducer<NetworkState> > sensesp::WiFiWatchdog::network_state_
protected

Definition at line 62 of file wifi_watchdog.h.

◆ policy_

WiFiWatchdogPolicy sensesp::WiFiWatchdog::policy_
protected

Definition at line 66 of file wifi_watchdog.h.

◆ poll_event_

reactesp::RepeatEvent* sensesp::WiFiWatchdog::poll_event_ = nullptr
protected

Definition at line 64 of file wifi_watchdog.h.

◆ restart_event_

reactesp::DelayEvent* sensesp::WiFiWatchdog::restart_event_ = nullptr
protected

Definition at line 65 of file wifi_watchdog.h.

◆ state_observer_id_

int sensesp::WiFiWatchdog::state_observer_id_ = -1
protected

Definition at line 63 of file wifi_watchdog.h.

◆ timeout_s_

int sensesp::WiFiWatchdog::timeout_s_
protected

Definition at line 61 of file wifi_watchdog.h.


The documentation for this class was generated from the following files: