|
AlteriomPainlessMesh v2.1.1
Easy ESP32/ESP8266 mesh networking with Alteriom IoT extensions
|
#include <wifi.hpp>


Classes | |
| struct | BridgeCandidate |
| struct | BridgeCoordinationState |
Public Types | |
| enum | BridgeSelectionStrategy { PRIORITY_BASED = 0 , ROUND_ROBIN = 1 , BEST_SIGNAL = 2 } |
Public Member Functions | |
| void | init (TSTRING ssid, TSTRING password, uint16_t port=5555, WiFiMode_t connectMode=WIFI_AP_STA, uint8_t channel=1, uint8_t hidden=0, uint8_t maxconn=MAX_CONN, TSTRING stationSSID="", TSTRING stationPassword="") |
| void | init (TSTRING ssid, TSTRING password, Scheduler *baseScheduler, uint16_t port=5555, WiFiMode_t connectMode=WIFI_AP_STA, uint8_t channel=1, uint8_t hidden=0, uint8_t maxconn=MAX_CONN, TSTRING stationSSID="", TSTRING stationPassword="") |
| bool | initAsBridge (TSTRING meshSSID, TSTRING meshPassword, TSTRING routerSSID, TSTRING routerPassword, Scheduler *baseScheduler, uint16_t port=5555) |
| bool | initAsBridge (TSTRING meshSSID, TSTRING meshPassword, TSTRING routerSSID, TSTRING routerPassword, Scheduler *baseScheduler, uint16_t port, uint8_t priority) |
| bool | initAsSharedGateway (TSTRING meshPrefix, TSTRING meshPassword, TSTRING routerSSID, TSTRING routerPassword, Scheduler *userScheduler, uint16_t port=5555, gateway::SharedGatewayConfig config=gateway::SharedGatewayConfig()) |
| bool | isSharedGatewayMode () const |
| const gateway::SharedGatewayConfig & | getSharedGatewayConfig () const |
| void | stationManual (TSTRING ssid, TSTRING password, uint16_t port=0, IPAddress remote_ip=IPAddress(0, 0, 0, 0)) |
| void | initStation () |
| void | handleStationDisconnectComplete () |
| void | tcpServerInit () |
| bool | tcpListening () |
| void | tcpConnect () |
| void | blockNodeAfterTCPFailure (IPAddress ip, uint32_t blockDurationMs=painlessmesh::tcp::TCP_FAILURE_BLOCK_DURATION_MS) |
| bool | setHostname (const char *hostname) |
| IPAddress | getStationIP () |
| IPAddress | getAPIP () |
| void | enableBridgeFailover (bool enabled) |
| void | setRouterCredentials (TSTRING ssid, TSTRING password) |
| void | setElectionTimeout (uint32_t timeoutMs) |
| void | setMinimumBridgeRSSI (int8_t minRSSI) |
| void | setElectionStartupDelay (uint32_t delayMs) |
| void | setElectionRandomDelay (uint32_t minMs, uint32_t maxMs) |
| void | onBridgeRoleChanged (std::function< void(bool isBridge, const TSTRING &reason)> callback) |
| void | onBridgeCoordination (std::function< void(const plugin::BridgeCoordinationPackage &, uint32_t)> callback) |
| void | onBridgeCoordinationChanged (std::function< void(const plugin::BridgeCoordinationPackage &, uint32_t, TSTRING)> callback) |
| void | enableMultiBridge (bool enabled) |
| void | setBridgeSelectionStrategy (BridgeSelectionStrategy strategy) |
| void | setMaxBridges (uint8_t maxBridges) |
| std::vector< uint32_t > | getActiveBridges () |
| bool | hasInternetConnection () |
| uint32_t | getRecommendedBridge () |
| bool | isMultiBridgeEnabled () const |
| void | checkForBridge () |
| void | checkForBridgeSoon () |
| void | stop () |
Public Member Functions inherited from painlessmesh::Mesh< Connection > | |
| void | init (uint32_t id) |
| void | init (Scheduler *scheduler, uint32_t id) |
| void | setRoot (bool on=true) |
| void | setContainsRoot (bool on=true) |
| bool | isRoot () |
| void | setDebugMsgTypes (uint16_t types) |
| void | stop () |
| void | update (void) |
| bool | sendSingle (uint32_t destId, TSTRING msg) |
| bool | sendSingle (uint32_t destId, TSTRING msg, uint8_t priorityLevel) |
| bool | sendSingle (uint32_t destId, TSTRING msg, const SendOptions &options) |
| bool | sendSingle (uint32_t destId, TSTRING msg, ack::deliveryCallback_t ackCallback, uint32_t ackTimeoutMs=5000) |
| bool | sendBroadcast (TSTRING msg, bool includeSelf=false) |
| bool | sendBroadcast (TSTRING msg, const SendOptions &options, bool includeSelf=false) |
| bool | sendBroadcast (TSTRING msg, bool includeSelf, ack::deliveryCallback_t ackCallback, uint32_t ackTimeoutMs=5000) |
| bool | sendBroadcast (TSTRING msg, Priority priorityLevel, IncludeSelf includeSelf=false) |
| size_t | checkAcks () |
| size_t | pendingAcks () const |
| bool | startDelayMeas (uint32_t id) |
| void | onReceive (receivedCallback_t onReceive) |
| void | onNewConnection (newConnectionCallback_t onNewConnection) |
| void | onDroppedConnection (droppedConnectionCallback_t onDroppedConnection) |
| void | onChangedConnections (changedConnectionsCallback_t onChangedConnections) |
| void | onNodeTimeAdjusted (nodeTimeAdjustedCallback_t onTimeAdjusted) |
| void | onNodeDelayReceived (nodeDelayCallback_t onDelayReceived) |
| void | onBridgeStatusChanged (bridgeStatusChangedCallback_t onBridgeStatusChanged) |
| bool | hasInternetConnection () |
| std::vector< uint32_t > | getNodesWithInternet () |
| std::vector< BridgeInfo > | getBridges () |
| BridgeInfo * | getPrimaryBridge () |
| BridgeInfo * | getLastKnownBridge () |
| bool | hasActiveMeshConnections () |
| bool | isBridge () |
| size_t | apChildren () |
| bool | overCapacity () |
| bool | capacityCheck (uint32_t freeHeap, uint32_t floor) |
| bool | isPrimaryGateway () |
| uint32_t | getPrimaryGateway () |
| std::list< uint32_t > | getGateways () |
| size_t | getGatewayCount () |
| void | onGatewayChanged (gatewayChangedCallback_t callback) |
| void | setBridgeStatusInterval (uint32_t intervalMs) |
| void | setBridgeTimeout (uint32_t timeoutMs) |
| void | enableBridgeStatusBroadcast (bool enabled) |
| bool | forgetBridge (uint32_t bridgeNodeId) |
| void | cleanupExpiredBridges () |
| void | enableBridgeCleanup () |
| void | disableBridgeCleanup () |
| bool | isBridgeCleanupEnabled () const |
| bool | hasLocalInternet () |
| bool | uplinkServesLocally () |
| void | onLocalInternetChanged (localInternetChangedCallback_t callback) |
| gateway::InternetStatus | getInternetStatus () |
| void | configureInternetHealthCheck (const gateway::SharedGatewayConfig &config) |
| void | setInternetCheckTarget (const TSTRING &host, uint16_t port=53) |
| void | setInternetCheckInterval (uint32_t intervalMs) |
| void | setInternetCheckTimeout (uint32_t timeoutMs) |
| bool | checkInternetNow () |
| void | enableInternetHealthCheck () |
| void | disableInternetHealthCheck () |
| bool | isInternetHealthCheckEnabled () const |
| void | resetInternetHealthStats () |
| uint32_t | sendToInternet (TSTRING destination, TSTRING payload, internetResultCallback_t callback, uint8_t priority=static_cast< uint8_t >(gateway::GatewayPriority::PRIORITY_NORMAL)) |
| uint32_t | sendToInternet (TSTRING destination, TSTRING payload, internetResponseCallback_t onResult, uint8_t priority=static_cast< uint8_t >(gateway::GatewayPriority::PRIORITY_NORMAL)) |
| void | setInternetRequestTimeout (uint32_t timeoutMs) |
| void | setInternetRetryCount (uint8_t retryCount) |
| void | setInternetRetryDelay (uint32_t delayMs) |
| void | setTcpRetryConfig (const painlessmesh::tcp::TcpRetryConfig &config) |
| painlessmesh::tcp::TcpRetryConfig | getTcpRetryConfig () const |
| size_t | getPendingInternetRequestCount () const |
| bool | cancelInternetRequest (uint32_t messageId) |
| void | enableSendToInternet () |
| void | disableSendToInternet () |
| bool | isSendToInternetEnabled () const |
| void | sendGatewayAck (const gateway::GatewayDataPackage &request, bool success, uint16_t httpStatus, const TSTRING &error, std::shared_ptr< Connection > ingressConnection=nullptr, const TSTRING &response=TSTRING(), int8_t retryable=-1, uint32_t retryAfterMs=0) |
| void | updateBridgeStatus (uint32_t bridgeNodeId, bool internetConnected, int8_t routerRSSI, uint8_t routerChannel, uint32_t uptime, TSTRING gatewayIP, uint32_t timestamp) |
| bool | enableRTC (rtc::RTCInterface *rtcInterface) |
| void | disableRTC () |
| bool | syncRTCFromNTP (uint32_t ntpTimestamp) |
| uint32_t | getAccurateTime () |
| bool | hasRTC () const |
| rtc::RTCType | getRTCType () const |
| uint32_t | getTimeSinceRTCSync () const |
| void | onRTCSyncComplete (rtcSyncCompleteCallback_t onRTCSyncComplete) |
| void | setTimeAuthority (bool hasAuthority) |
| bool | getTimeAuthority () const |
| void | enableMessageQueue (bool enabled, uint32_t maxSize=1000) |
| uint32_t | queueMessage (const TSTRING &payload, const TSTRING &destination="", MessagePriority priority=PRIORITY_NORMAL) |
| std::vector< QueuedMessage > | flushMessageQueue () |
| bool | removeQueuedMessage (uint32_t messageId) |
| uint32_t | incrementQueuedMessageAttempts (uint32_t messageId) |
| uint32_t | getQueuedMessageCount (MessagePriority priority) |
| uint32_t | getQueuedMessageCount () |
| QueueStats | getQueueStats () |
| void | onQueueStateChanged (queueStateChangedCallback_t callback) |
| uint32_t | pruneQueue (uint32_t maxAgeMs) |
| void | clearQueue () |
| bool | isConnected (uint32_t nodeId) |
| std::list< uint32_t > | getNodeList (bool includeSelf=false) |
| TSTRING | subConnectionJson (bool pretty=false) |
| std::vector< ConnectionInfo > | getConnectionDetails () |
| int | getHopCount (uint32_t nodeId) |
| std::map< uint32_t, uint32_t > | getRoutingTable () |
| std::vector< uint32_t > | getPathToNode (uint32_t nodeId) |
| BridgeHealthMetrics | getBridgeHealthMetrics () |
| void | resetHealthMetrics () |
| TSTRING | getHealthMetricsJSON () |
| void | onHealthMetricsUpdate (std::function< void(BridgeHealthMetrics)> callback, uint32_t intervalMs=60000) |
| void | enableDiagnostics (bool enabled=true) |
| BridgeStatus | getBridgeStatus () |
| std::vector< ElectionRecord > | getElectionHistory () |
| BridgeChangeEvent | getLastBridgeChange () |
| TSTRING | exportTopologyDOT () |
| BridgeTestResult | testBridgeConnectivity () |
| bool | isBridgeReachable (uint32_t bridgeNodeId) |
| TSTRING | getDiagnosticReport () |
| std::shared_ptr< Task > | addTask (unsigned long aInterval, long aIterations, std::function< void()> aCallback) |
| std::shared_ptr< Task > | addTask (std::function< void()> aCallback) |
| std::shared_ptr< Task > | addTask (std::function< void()> aCallback, unsigned long delayMs) |
| ~Mesh () | |
| void | startTimeSync (std::shared_ptr< Connection > conn) |
| bool | getNodeNeighbors (const protocol::NodeTree &tree, uint32_t nodeId, std::list< uint32_t > &neighbors, uint32_t parent=0) const |
| bool | closeConnectionSTA () |
| void | eraseClosedConnections () |
| bool | semaphoreTake () |
| void | semaphoreGive () |
Public Member Functions inherited from painlessmesh::ntp::MeshTime | |
| uint32_t | getNodeTime () |
Public Member Functions inherited from painlessmesh::plugin::PackageHandler< T > | |
| void | stop (Scheduler *scheduler=nullptr) |
| ~PackageHandler () | |
| bool | sendPackage (const protocol::PackageInterface *pkg) |
| void | onPackage (int type, std::function< bool(protocol::Variant &)> function) |
| std::shared_ptr< Task > | addTask (Scheduler &scheduler, unsigned long aInterval, long aIterations, std::function< void()> aCallback) |
| std::shared_ptr< Task > | addTask (Scheduler &scheduler, std::function< void()> aCallback) |
Public Member Functions inherited from painlessmesh::layout::Layout< T > | |
| uint32_t | getNodeId () const |
| bool | isRoot () const |
| protocol::NodeTree | asNodeTree () |
Static Public Attributes | |
| static constexpr uint8_t | TCP_STATE_LISTEN = 1 |
Static Public Attributes inherited from painlessmesh::Mesh< Connection > | |
| static constexpr uint32_t | ESP8266_CAPACITY_FLOOR |
| static constexpr uint32_t | CAPACITY_WARN_INTERVAL_MS |
| static const size_t | MAX_KNOWN_BRIDGES |
| static const size_t | MAX_ELECTION_HISTORY |
Protected Types | |
| enum | ElectionState { ELECTION_IDLE , ELECTION_SCANNING , ELECTION_COLLECTING } |
Protected Member Functions | |
| void | init (Scheduler *scheduler, uint32_t id) |
| void | init (uint32_t id) |
| void | apInit (uint32_t nodeId) |
| void | initBridgeStatusBroadcast () |
| void | initBridgeCoordination () |
| void | sendBridgeCoordination () |
| int8_t | scanRouterSignalStrength (TSTRING routerSSID, uint8_t *routerChannel=nullptr) |
| void | startBridgeElection () |
| void | evaluateElection () |
| void | promoteToBridge (uint8_t routerChannel) |
| bool | attemptIsolatedBridgePromotion () |
| void | handleBridgeElection (uint32_t fromNode, int8_t routerRSSI, uint8_t routerChannel, uint32_t uptime, uint32_t freeMemory) |
| void | sendBridgeStatus (bool leaving=false) |
| bool | hasActualInternetAccess () |
| bool | detectCaptivePortal () |
| void | initGatewayInternetHandler () |
| void | probeUplinkAfterAssociation () |
| void | eventHandleInit () |
| void | initSharedGatewayMonitoring () |
| void | monitorRouterConnection () |
| void | scheduleRouterReconnect () |
| void | attemptRouterReconnect () |
Protected Member Functions inherited from painlessmesh::Mesh< Connection > | |
| void | reclaimRetiredSchedulers () |
| void | queueBroadcastAck (uint32_t origin, uint32_t msgId) |
| void | ensureAckScheduling () |
| void | setScheduler (Scheduler *baseScheduler) |
Protected Member Functions inherited from painlessmesh::plugin::PackageHandler< T > | |
| void | reclaimQuarantinedTasks () |
Static Protected Attributes | |
| static const uint8_t | MAX_ISOLATED_BRIDGE_RETRY_ATTEMPTS |
| static const uint32_t | isolatedBridgeRetryIntervalMs |
| static const uint32_t | isolatedBridgeRetryResetIntervalMs |
| static const uint16_t | ISOLATED_BRIDGE_RETRY_SCAN_THRESHOLD |
| static const uint32_t | ASYNC_PROMOTION_DELAY_MS |
| static const uint8_t | MAX_ROUTER_RECONNECT_ATTEMPTS = 10 |
| static const uint32_t | ROUTER_RECONNECT_BASE_INTERVAL |
| static const uint32_t | ROUTER_RECONNECT_MAX_INTERVAL |
| static const int | ROUTER_CONNECTION_TIMEOUT_SECONDS |
| static const uint8_t | MIN_WIFI_CHANNEL = 1 |
| static const uint8_t | MAX_WIFI_CHANNEL |
Static Protected Attributes inherited from painlessmesh::Mesh< Connection > | |
| static constexpr unsigned long | ACK_CHECK_INTERVAL_MS |
| static constexpr uint32_t | ACK_BROADCAST_JITTER_MS |
| static constexpr uint32_t | ACK_BROADCAST_MIN_TIMEOUT_MS |
| static constexpr size_t | MAX_QUEUED_BROADCAST_ACKS |
Friends | |
| class | ::StationScan |
|
protected |
|
inlineprotected |
|
inlineprotected |
Attempt to promote an isolated node to bridge
This method handles the case where a node is isolated (no mesh connections) but has router credentials. Unlike the election-based promotion, this directly attempts to connect to the router without requiring mesh connectivity.
This is useful for:
CRITICAL: This function is called from within a scheduled task (isolated bridge retry task). We MUST NOT call stop() synchronously here because that would clear the taskList while the current task is executing, causing a use-after-free crash when the task tries to return to scheduler.
|
inlineprotected |
Attempt to reconnect to the router
|
inline |
Block a node after TCP connection failure
This prevents the node from being repeatedly selected for connection attempts when its TCP server is unresponsive. The block is temporary and will expire after the configured duration.
| ip | The IP address of the failed node |
| blockDurationMs | Duration to block the node in milliseconds (default: 60s) |
|
inline |
|
inline |
|
inlineprotected |
Detect captive portal by making a lightweight HTTP request
Captive portals often allow DNS resolution but intercept HTTP requests, returning redirects, cached responses (HTTP 203), or their own HTML. This function makes a simple HTTP GET request to a known endpoint and verifies the response to detect such interference.
Test endpoint used:
|
inline |
Enable or disable automatic bridge failover
When enabled, nodes will participate in bridge elections if the primary bridge goes offline and they have router credentials configured.
| enabled | true to enable automatic failover (default), false to disable |
|
inline |
Enable or disable multi-bridge coordination mode
When enabled, multiple bridges can operate simultaneously for:
| enabled | true to enable multi-bridge mode, false for single-bridge (default) |
|
inlineprotected |
Evaluate election and determine winner Called after election timeout expires
|
inlineprotected |
|
inline |
Get list of all active bridges (with Internet connection)
|
inline |
|
inline |
Get recommended bridge for message transmission
Uses the configured bridge selection strategy to pick the best bridge. Returns 0 if no suitable bridge is available.
|
inline |
Get the shared gateway configuration
|
inline |
|
inlineprotected |
Handle received bridge election package Called by package handler when election message arrives
|
inline |
Handle station disconnect completion Called after WiFi disconnect event is fully processed This ensures proper sequencing: disconnect -> event -> reconnect
|
inlineprotected |
Check if gateway has actual internet connectivity
Tests DNS resolution to detect scenarios where WiFi is connected but the router has no internet access. This provides early detection before attempting HTTP requests that would timeout or fail.
|
inline |
Check if any bridge/gateway in the mesh has Internet connectivity
IMPORTANT: This method checks if a GATEWAY node (bridge) in the mesh has Internet access, NOT whether THIS node can directly make HTTP/HTTPS requests.
Regular mesh nodes do NOT have direct IP routing to the Internet. They only communicate via the painlessMesh protocol. To send data to the Internet from a regular node, you must use sendToInternet() which routes through a gateway, or use initAsSharedGateway(meshSSID, meshPwd, ROUTER_SSID, ROUTER_PWD, scheduler, port) to give all nodes direct router access (requires router credentials).
Override of base class method to also check if THIS node is a bridge with Internet connectivity, not just other bridges in the mesh.
|
inlineprotected |
|
inline |
Initialize the mesh network
Add this to your setup() function. This routine does the following things:
| ssid | The name of your mesh. All nodes share same AP ssid. They are distinguished by BSSID. |
| password | Wifi password to your mesh. |
| port | the TCP port that you want the mesh server to run on. Defaults to 5555 if not specified. |
| connectMode | Switch between WIFI_AP, WIFI_STA and WIFI_AP_STA (default) mode |
|
inline |
Initialize the mesh network
Add this to your setup() function. This routine does the following things:
| ssid | The name of your mesh. All nodes share same AP ssid. They are distinguished by BSSID. |
| password | Wifi password to your mesh. |
| port | the TCP port that you want the mesh server to run on. Defaults to 5555 if not specified. |
| connectMode | Switch between WIFI_AP, WIFI_STA and WIFI_AP_STA (default) mode |
|
inlineprotected |
|
inline |
Initialize mesh as a bridge node with priority (for multi-bridge mode)
This overload adds bridge priority configuration for multi-bridge deployments. Priority determines which bridge is preferred when multiple bridges are available.
| meshSSID | The name of your mesh network |
| meshPassword | WiFi password for the mesh |
| routerSSID | SSID of the router to connect to |
| routerPassword | Password for the router |
| baseScheduler | Task scheduler for mesh operations |
| port | TCP port for mesh communication (default: 5555) |
| priority | Bridge priority: 10=highest (primary), 5=medium (secondary), 1=lowest (default: 5) |
|
inline |
Initialize mesh as a bridge node with automatic channel detection
This method connects to a router first, detects its channel, then initializes the mesh on the same channel. This ensures the bridge can maintain both router and mesh connections on the same channel.
The bridge node will automatically:
| meshSSID | The name of your mesh network |
| meshPassword | WiFi password for the mesh |
| routerSSID | SSID of the router to connect to |
| routerPassword | Password for the router |
| baseScheduler | Task scheduler for mesh operations |
| port | TCP port for mesh communication (default: 5555) |
|
inline |
Initialize mesh as a shared gateway node
This method initializes all mesh nodes in AP+STA mode with router connectivity. Unlike initAsBridge() which creates a single bridge node, initAsSharedGateway() allows all nodes to connect to the router while maintaining mesh communication.
Key features:
| meshPrefix | The name prefix for the mesh network |
| meshPassword | WiFi password for the mesh network |
| routerSSID | SSID of the router to connect to |
| routerPassword | Password for the router |
| userScheduler | Task scheduler for mesh operations |
| port | TCP port for mesh communication (default: 5555) |
| config | SharedGatewayConfig with advanced settings (optional) |
|
inlineprotected |
Initialize bridge coordination broadcasting Sets up periodic coordination messages between bridges
|
inlineprotected |
Initialize bridge status broadcasting Sets up a periodic task to broadcast bridge status to the mesh
|
inlineprotected |
Initialize gateway Internet handler Registers GATEWAY_DATA package handler for bridge/gateway nodes
This handler processes GATEWAY_DATA packages from mesh nodes requesting HTTP/HTTPS requests to Internet destinations. It validates connectivity, makes the request, and sends back a GATEWAY_ACK with the result.
Security notes:
Limitations:
|
inlineprotected |
Initialize shared gateway monitoring
Sets up periodic monitoring of router connection and automatic reconnection logic for shared gateway mode.
|
inline |
|
inline |
Check if multi-bridge mode is enabled
|
inline |
Check if shared gateway mode is enabled
|
inlineprotected |
Monitor router connection in shared gateway mode
Checks router connectivity and triggers reconnection if needed.
|
inline |
Set callback for bridge coordination messages
Called every time a coordination message (Type 613) is received from another bridge. Useful for monitoring bridge health and status.
For non-bridge nodes, this also registers a Type 613 handler so that regular mesh nodes can monitor bridge coordination traffic.
| callback | Function called with the coordination package and sender node ID |
|
inline |
Set callback for bridge coordination state changes
Called when a new bridge is discovered, an existing bridge changes its priority/role/load, or a bridge is lost (no coordination message for 60s).
| callback | Function called with the coordination package, sender node ID, and change type ("new", "updated", or "lost") |
|
inline |
Set callback for when this node's bridge role changes
| callback | Function to call when role changes |
|
inlineprotected |
The station just got an IP. On a node that runs the Internet health check – a bridge or a shared gateway, whose station is the manual router link – the last probe most likely ran during association and failed, and the next is a full interval away (issue #450). Probe again now, from the scheduler rather than the Wi-Fi event task, so hasLocalInternet() and the bridge's own sends stop waiting out the interval. A regular node's mesh station never enables the check and is left alone.
|
inlineprotected |
Promote this node to bridge role Called when node wins election
CRITICAL: This function is called from within evaluateElection() which runs as a scheduled task. We MUST NOT call stop() synchronously here because that would clear the taskList while the current task is executing, causing a use-after-free crash when the task tries to return to scheduler.
Instead, we schedule the actual promotion work to run after the current task completes, allowing safe cleanup of task structures.
|
inlineprotected |
Scan for router and return its signal strength
| routerSSID | SSID of router to scan for |
|
inlineprotected |
Schedule router reconnection with exponential backoff
|
inlineprotected |
Send bridge coordination message to other bridges Called periodically in multi-bridge mode
|
inlineprotected |
Send bridge status broadcast Called periodically by bridge nodes to report connectivity status
|
inline |
Set bridge selection strategy for multi-bridge mode
| strategy | Selection strategy:
|
|
inline |
Set the random delay range for bridge elections
When multiple nodes detect missing bridge simultaneously, randomized delays prevent all nodes from starting elections at the same instant. Longer delays provide more time for mesh discovery and reduce split-brain risk.
| minMs | Minimum random delay in milliseconds (default: 1000 = 1 second) |
| maxMs | Maximum random delay in milliseconds (default: 3000 = 3 seconds) |
|
inline |
Set the startup delay before first bridge election check
Allows time for mesh network formation before starting bridge elections. Longer delays reduce the risk of split-brain scenarios when multiple nodes start simultaneously, ensuring nodes discover each other before elections.
| delayMs | Startup delay in milliseconds (default: 60000 = 60 seconds, min: 10000) |
|
inline |
Set the election timeout (how long to collect candidates)
| timeoutMs | Timeout in milliseconds (default: 5000 = 5 seconds) |
|
inline |
|
inline |
Set maximum number of concurrent bridges in multi-bridge mode
| maxBridges | Maximum bridges to track (default: 2, max: 5) |
|
inline |
Set the minimum RSSI required for bridge election
Prevents nodes with poor router signal from becoming bridges in isolated elections. When a node is the only candidate, it must meet this threshold. When multiple candidates exist, the best RSSI wins regardless of threshold.
| minRSSI | Minimum RSSI in dBm (default: -80 dBm, range: -100 to -30) |
Set router credentials for bridge election participation
Nodes must have router credentials configured to participate in bridge elections. When a bridge fails, only nodes with credentials can become the new bridge.
| ssid | Router SSID |
| password | Router password |
|
inlineprotected |
Start bridge election process Called when primary bridge failure is detected
|
inline |
Connect (as a station) to a specified network and ip
You can pass {0,0,0,0} as IP to have it connect to the gateway
This stops the node from scanning for other (non specified) nodes and you should probably also use this node as an anchor: setAnchor(true)
|
inline |
|
inline |
Establish TCP connection to mesh network
This method is called by WiFi event handlers when station gets IP address. It creates a TCP client connection to the mesh network gateway.
Architecture Note: This is intentionally kept in the Mesh class rather than extracted to a separate StationConnection class because:
TCP Connection Retry: The TCP connection now includes automatic retry with exponential backoff. If the initial connection fails (error -14 ERR_CONN or other errors), the system will retry up to the configured maxRetries times before triggering a full WiFi reconnection cycle (see setTcpRetryConfig()). This helps handle:
|
inline |
Whether this node's TCP listener exists and is in LISTEN.
The state peers depend on and nothing else reports: a node whose listener was never created (#466 crashed before it could be) or was re-created not listening (#435's promoted bridge served nothing for two minutes) is reachable only through connections it made outbound, and nothing can join through it. Cheap enough to put in a health report.
|
inline |
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
Helper method to send gateway acknowledgment Hosts that recently failed to resolve; fed on ESP32 only, see the GATEWAY_DATA handler.
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticconstexpr |
lwIP's LISTEN, which AsyncServer::status() returns as the pcb's state on both cores (ESPAsyncTCP and ESP32Async/AsyncTCP alike). Named rather than written as 1 because status() also answers 0 – lwIP's CLOSED – when the server holds no pcb at all, so the literal read as if it conflated the two. It does not: a listener is listening, or it is not.