AlteriomPainlessMesh v2.1.1
Easy ESP32/ESP8266 mesh networking with Alteriom IoT extensions
Loading...
Searching...
No Matches
Public Member Functions | List of all members
painlessmesh::gateway::InternetHealthChecker Class Reference

Internet Health Checker class for periodic connectivity monitoring. More...

#include <gateway.hpp>

Public Member Functions

 InternetHealthChecker ()=default
 
void setConfig (const SharedGatewayConfig &config)
 Configure the health checker with gateway settings.
 
void setCheckTarget (const TSTRING &host, uint16_t port=53)
 Set custom check host and port.
 
void setCheckInterval (uint32_t intervalMs)
 Set check interval.
 
void setCheckTimeout (uint32_t timeoutMs)
 Set check timeout.
 
void onConnectivityChanged (InternetChangedCallback_t callback)
 Register callback for connectivity changes.
 
bool hasLocalInternet () const
 Check if local Internet is currently available.
 
InternetStatus getStatus () const
 Get detailed Internet status.
 
bool checkNow ()
 Perform an immediate Internet connectivity check.
 
bool checkOnDemand ()
 Probe once outside the schedule, for a caller that needs the answer now (issue #450)
 
uint32_t getCheckInterval () const
 Get check interval.
 
uint32_t getCheckTimeout () const
 Get check timeout.
 
TSTRING getCheckHost () const
 Get check host.
 
uint16_t getCheckPort () const
 Get check port.
 
void resetStats ()
 Reset all statistics.
 

Detailed Description

Internet Health Checker class for periodic connectivity monitoring.

This class performs periodic TCP connection tests to verify Internet connectivity. It is designed to be non-blocking and work with the TaskScheduler for asynchronous operation.

PLATFORM SUPPORT:

Example usage:

checker.setConfig(gatewayConfig);
checker.onConnectivityChanged([](bool available) {
Serial.printf("Internet %s\n", available ? "connected" : "disconnected");
});
checker.start(scheduler);
Internet Health Checker class for periodic connectivity monitoring.
Definition gateway.hpp:498
void onConnectivityChanged(InternetChangedCallback_t callback)
Register callback for connectivity changes.
Definition gateway.hpp:547
void setConfig(const SharedGatewayConfig &config)
Configure the health checker with gateway settings.
Definition gateway.hpp:506

Constructor & Destructor Documentation

◆ InternetHealthChecker()

painlessmesh::gateway::InternetHealthChecker::InternetHealthChecker ( )
default

Member Function Documentation

◆ checkNow()

bool painlessmesh::gateway::InternetHealthChecker::checkNow ( )
inline

Perform an immediate Internet connectivity check.

This method performs a synchronous TCP connection test. On ESP32/ESP8266, it uses WiFiClient. In test environment, connectivity is mocked.

Returns
true if connection succeeded

◆ checkOnDemand()

bool painlessmesh::gateway::InternetHealthChecker::checkOnDemand ( )
inline

Probe once outside the schedule, for a caller that needs the answer now (issue #450)

A bridge's first periodic probe runs while its station is still associating and fails, and the next is a full interval away. A send in that window may spend one extra probe to learn that the uplink has come up since. One: the probe is a blocking connect with a timeout, so the budget is a single on-demand probe per periodic one. A node whose uplink really is down pays it once per interval, not on every call.

Returns
true if Internet is reachable now

◆ getCheckHost()

TSTRING painlessmesh::gateway::InternetHealthChecker::getCheckHost ( ) const
inline

Get check host.

Returns
Host being checked

◆ getCheckInterval()

uint32_t painlessmesh::gateway::InternetHealthChecker::getCheckInterval ( ) const
inline

Get check interval.

Returns
Check interval in milliseconds

◆ getCheckPort()

uint16_t painlessmesh::gateway::InternetHealthChecker::getCheckPort ( ) const
inline

Get check port.

Returns
Port being checked

◆ getCheckTimeout()

uint32_t painlessmesh::gateway::InternetHealthChecker::getCheckTimeout ( ) const
inline

Get check timeout.

Returns
Check timeout in milliseconds

◆ getStatus()

InternetStatus painlessmesh::gateway::InternetHealthChecker::getStatus ( ) const
inline

Get detailed Internet status.

Returns
InternetStatus structure with full details

◆ hasLocalInternet()

bool painlessmesh::gateway::InternetHealthChecker::hasLocalInternet ( ) const
inline

Check if local Internet is currently available.

Returns
true if last check succeeded

◆ onConnectivityChanged()

void painlessmesh::gateway::InternetHealthChecker::onConnectivityChanged ( InternetChangedCallback_t  callback)
inline

Register callback for connectivity changes.

Parameters
callbackFunction to call when connectivity status changes

◆ resetStats()

void painlessmesh::gateway::InternetHealthChecker::resetStats ( )
inline

Reset all statistics.

◆ setCheckInterval()

void painlessmesh::gateway::InternetHealthChecker::setCheckInterval ( uint32_t  intervalMs)
inline

Set check interval.

Parameters
intervalMsInterval between checks in milliseconds

◆ setCheckTarget()

void painlessmesh::gateway::InternetHealthChecker::setCheckTarget ( const TSTRING &  host,
uint16_t  port = 53 
)
inline

Set custom check host and port.

Parameters
hostHost to check (IP address or hostname)
portPort to connect to (default: 53 for DNS)

◆ setCheckTimeout()

void painlessmesh::gateway::InternetHealthChecker::setCheckTimeout ( uint32_t  timeoutMs)
inline

Set check timeout.

Parameters
timeoutMsTimeout for each check in milliseconds

◆ setConfig()

void painlessmesh::gateway::InternetHealthChecker::setConfig ( const SharedGatewayConfig &  config)
inline

Configure the health checker with gateway settings.

Parameters
configSharedGatewayConfig with check parameters

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