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


Classes | |
| struct | ConnectionInfo |
Public Member Functions | |
| 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) |
| size_t | checkAcks () |
| size_t | pendingAcks () const |
| template<typename Priority , typename IncludeSelf = bool, typename std::enable_if<(std::is_integral< typename std::decay< Priority >::type >::value||std::is_enum< typename std::decay< Priority >::type >::value) &&!std::is_same< typename std::decay< Priority >::type, bool >::value &&std::is_same< typename std::decay< IncludeSelf >::type, bool >::value, int >::type = 0> | |
| bool | sendBroadcast (TSTRING msg, Priority priorityLevel, IncludeSelf includeSelf=false) |
| 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< T > 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< T > 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 uint32_t | ESP8266_CAPACITY_FLOOR = 12 * 1024 |
| static constexpr uint32_t | CAPACITY_WARN_INTERVAL_MS = 5 * 60 * 1000 |
| static const size_t | MAX_KNOWN_BRIDGES = 20 |
| static const size_t | MAX_ELECTION_HISTORY = 10 |
Protected Member Functions | |
| 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 () |
Protected Attributes | |
| std::list< Scheduler * > | retiredSchedulers = {} |
| ack::AckTracker | ackTracker |
| std::shared_ptr< Task > | ackCheckTask |
| std::vector< std::pair< uint32_t, uint32_t > > | pendingBroadcastAcks |
| std::shared_ptr< Task > | broadcastAckTask |
Protected Attributes inherited from painlessmesh::plugin::PackageHandler< T > | |
| callback::MeshPackageCallbackList< T > | callbackList |
| std::list< std::shared_ptr< Task > > | taskList = {} |
| std::list< std::pair< Scheduler *, std::shared_ptr< Task > > > | quarantinedTasks |
Protected Attributes inherited from painlessmesh::layout::Layout< T > | |
| uint32_t | nodeId = 0 |
| bool | root = false |
| bool | hasTimeAuthority = false |
Static Protected Attributes | |
| static constexpr unsigned long | ACK_CHECK_INTERVAL_MS |
| static constexpr uint32_t | ACK_BROADCAST_JITTER_MS = 50 |
| static constexpr uint32_t | ACK_BROADCAST_MIN_TIMEOUT_MS = 1000 |
| static constexpr size_t | MAX_QUEUED_BROADCAST_ACKS |
Friends | |
| void | onDataCb (void *, AsyncClient *, void *, size_t) |
| void | tcpSentCb (void *, AsyncClient *, size_t, uint32_t) |
| void | meshRecvCb (void *, AsyncClient *, void *, size_t) |
| void | painlessmesh::ntp::handleTimeSync (Mesh &, painlessmesh::protocol::TimeSync, std::shared_ptr< T >, uint32_t) |
| void | painlessmesh::ntp::handleTimeDelay (Mesh &, painlessmesh::protocol::TimeDelay, std::shared_ptr< T >, uint32_t) |
| void | painlessmesh::router::handleNodeSync (Mesh &, protocol::NodeTree, std::shared_ptr< T > conn) |
| void | painlessmesh::tcp::initServer (AsyncServer &, Mesh &) |
| void | painlessmesh::tcp::connect (AsyncClient &, IPAddress, uint16_t, Mesh &, uint8_t) |
Main api class for the mesh
Brings all the functions together except for the WiFi functions
|
inline |
|
inline |
|
inline |
Add a one-shot delayed task
| aCallback | Function to call after the delay |
| delayMs | Delay in milliseconds before executing the callback |
|
inline |
|
inline |
Live connections for which this node is the access point.
Every one of them holds send and receive buffers on this node's heap. A leaf has none; a node the mesh routes through has as many as attach.
|
inline |
Cancel a pending Internet request
| messageId | Message ID to cancel |
|
inline |
Evaluate the capacity rule now. Returns the new state.
| freeHeap | the part's current free heap in bytes |
| floor | below this, with more than one child, is over capacity |
|
inline |
Process pending delivery acknowledgments (non-blocking poll)
Schedules timeout callbacks for messages whose acknowledgment window has elapsed. Callbacks run on a later scheduler pass, after the current mesh dispatch has unwound. This also happens automatically inside mesh.update(), so calling it manually is only needed in tight loops that want prompt timeout detection.
|
inline |
Perform an immediate Internet connectivity check
Bypasses the periodic check schedule and performs an immediate check. Fires the onLocalInternetChanged callback if status changes.
|
inline |
|
inline |
Clear all messages from the queue
|
inline |
|
inline |
Configure Internet health checker with gateway settings
Sets up the health checker with parameters from SharedGatewayConfig. This should be called before enabling gateway mode.
| config | Gateway configuration with check parameters |
|
inline |
Disable periodic cleanup of expired bridge entries
|
inline |
Disable periodic Internet health checking
|
inline |
Disable RTC integration
|
inline |
Disable the sendToInternet() API
|
inline |
Enable periodic cleanup of expired bridge entries
Starts a background task that periodically removes stale bridge entries. The cleanup runs at the same interval as the bridge timeout (default 60 seconds).
This is recommended for all nodes to prevent memory growth from accumulating stale bridge entries.
|
inline |
Enable or disable bridge status broadcasting (bridge nodes only)
| enabled | true to enable broadcasting (default), false to disable |
|
inline |
Enable or disable diagnostics collection
When enabled, the mesh will track election history, bridge changes, and other diagnostic information. This has minimal overhead.
| enabled | true to enable diagnostics (default), false to disable |
|
inline |
Enable periodic Internet health checking
Starts a TaskScheduler task that periodically checks Internet connectivity. The check interval is configured via setInternetCheckInterval() or configureInternetHealthCheck().
|
inline |
Enable or disable the manual message queue for offline mode
When enabled, allocates a MessageQueue that your application can push into while an upstream (MQTT/HTTP/etc.) is unreachable. The mesh does NOT flush the queue automatically and does NOT observe connectivity changes — the app is responsible for detecting when to drain it via flushMessageQueue() + removeQueuedMessage().
Wire it to your own connectivity signal, for example onLocalInternetChanged on the bridge node or onBridgeStatusChanged on downstream nodes.
| enabled | True to enable queueing, false to disable |
| maxSize | Maximum number of messages in queue (default 1000) |
|
inline |
Enable RTC integration for offline timekeeping
Allows nodes to maintain accurate timestamps even when Internet/bridge is unavailable. User must provide an implementation of RTCInterface for their specific RTC hardware.
| rtcInterface | Pointer to user's RTC implementation |
|
inline |
Enable the sendToInternet() API
This registers the handler for GatewayAckPackage (Type 621) and starts the periodic cleanup of timed-out requests.
Call this after mesh.init() to enable the sendToInternet() functionality.
|
inlineprotected |
Make sure the periodic ack-timeout task is running
The task disables itself as soon as no acknowledgments are pending, so there is zero scheduler overhead when the ack API is not in use.
|
inline |
|
inline |
Export topology as DOT format (Graphviz)
Generates a GraphViz DOT format representation of the mesh topology. Can be visualized using Graphviz tools.
|
inline |
Return a snapshot of all queued messages for manual delivery
This does NOT transmit anything and does NOT clear the queue. The application is responsible for actually sending each message and calling removeQueuedMessage(id) for each one that succeeded. Messages left in the queue remain available for retry on the next flush.
|
inline |
Clean up expired bridge entries that haven't reported recently
Removes bridges that haven't sent a status update within the timeout period. This helps maintain an accurate list of available gateways and prevents the bridge list from growing unbounded.
Called periodically when bridge cleanup is enabled, or can be called manually.
Forget one bridge now: it announced that it is stepping down.
Returns whether it was known.
|
inline |
Get accurate time with RTC fallback
Returns time from RTC if available, otherwise falls back to mesh time. This provides the most accurate timestamp available to the node.
|
inline |
Get bridge health metrics
Collects comprehensive health metrics including connectivity, signal quality, traffic, and performance data. Useful for monitoring and troubleshooting.
|
inline |
Get list of all known bridges in the mesh
|
inline |
Get current bridge status
Returns information about this node's bridge role and connectivity status
|
inline |
Get detailed connection information for all direct neighbors
|
inline |
Get comprehensive diagnostic report
Generates a human-readable diagnostic report with mesh status, bridge info, connectivity, and performance metrics. Useful for debugging and monitoring.
|
inline |
Get election history
Returns list of recent bridge elections if diagnostics are enabled. History is limited to last 10 elections.
|
inline |
Get count of available gateways
Returns the number of healthy bridges with active Internet connectivity.
|
inline |
Get list of all nodes with Internet access
Returns node IDs of all healthy bridges with active Internet connectivity. Only bridges that have reported status within the timeout period are included.
This method provides the same data as getNodesWithInternet() but returns a std::list for consistency with other node list methods in painlessMesh.
|
inline |
Export health metrics as JSON string
Generates a JSON representation of current health metrics for easy integration with monitoring tools, MQTT publishing, or logging.
|
inline |
Get hop count to specific node Returns -1 if node is unreachable
|
inline |
Get detailed status of local Internet connectivity
Returns comprehensive information about Internet connectivity checks including success/failure counts, timing, and error messages.
|
inline |
Get last bridge change event
Returns information about the most recent bridge change
|
inline |
Get the last known bridge with Internet connection (regardless of lastSeen timeout)
Unlike getPrimaryBridge(), this method returns the best known bridge even if the lastSeen timestamp is stale. This is useful when the local node is temporarily disconnected from the mesh and cannot receive bridge status updates.
The returned bridge may not be currently reachable, but represents the last known good configuration.
|
inline |
Get a list of all known nodes.
This includes nodes that are both directly and indirectly connected to the current node.
|
inline |
Helper function to get direct neighbors of a node from the mesh topology tree
| tree | The node tree to search |
| nodeId | The node whose neighbors we want to find |
| neighbors | Output list of neighbor node IDs |
| parent | The parent node ID (used during recursion, 0 means no parent) |
|
inline |
Get list of nodes that currently have Internet access
Returns node IDs of all healthy bridges with active Internet connectivity. Only bridges that have reported status within the timeout period are included.
|
inline |
Get complete path from this node to target node
Returns a vector containing the complete path of node IDs from this node to the target node, including both endpoints. Uses BFS to find the shortest path. Returns an empty vector if the target is unreachable.
| nodeId | The target node ID |
|
inline |
Get number of pending Internet requests
|
inline |
Get the primary (best) bridge node
Primary bridge is selected based on:
This method now ALWAYS requires healthy (recent) bridge status to prevent routing messages to unreachable or outdated bridges when mesh connectivity is lost. Without active mesh connections and fresh status, we cannot reliably route messages to any bridge.
If you need access to the last known bridge regardless of health status, use getLastKnownBridge() instead.
|
inline |
Get the node ID of the current primary gateway
Returns the node ID of the bridge with the best RSSI to the router that has Internet connectivity, or 0 if no gateway is available.
|
inline |
|
inline |
Get number of queued messages
| priority | Optional priority level to count (counts all if not specified) |
|
inline |
Get queue statistics
|
inline |
Get routing table as map (destination -> next hop)
Uses BFS to build a complete routing table with next-hop information for all reachable nodes in the mesh. For direct connections, the next hop is the node itself. For multi-hop paths, the next hop is the first node on the shortest path to the destination.
|
inline |
Get RTC type
|
inline |
Get the active TCP retry configuration
|
inline |
Check if this node has time authority
|
inline |
Get time since last RTC sync
|
inline |
Check if this node has active mesh connections
Returns true if this node has at least one active connection to other mesh nodes. When false, the node is isolated and cannot receive any mesh messages including bridge status updates.
This is useful for distinguishing between:
|
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 over the painlessMesh protocol. To send data to the Internet from a regular node, you must either:
Use hasLocalInternet() to check if THIS specific node has direct Internet access.
This method now ALWAYS requires healthy (recent) bridge status to prevent false positives when mesh connectivity is lost. Without active mesh connections, stale bridge data cannot be relied upon, as the bridge may have lost Internet connectivity or become unreachable.
|
inline |
Check if THIS node has direct local Internet access
This method checks whether this specific node can directly reach the Internet, as opposed to hasInternetConnection() which checks if any bridge in the mesh has Internet access.
For gateway/bridge nodes, this returns the result of the local health check. For regular nodes, this typically returns false unless they have their own Internet connection.
|
inline |
Check if RTC is enabled and available
|
inline |
Increment send attempt counter for a message
| messageId | ID of message |
|
inline |
|
inline |
|
inline |
Check if this node is acting as a bridge
|
inline |
Check if bridge cleanup is enabled
|
inline |
Check if specific bridge is reachable
Tests if the specified bridge node can be reached from this node.
| bridgeNodeId | Bridge node ID to test |
|
inline |
Are we connected/know a route to the given node?
| nodeId | The nodeId we are looking for |
|
inline |
Check if Internet health checking is enabled
|
inline |
Check if this node is the primary gateway
A node is the primary gateway if it's the bridge with the best RSSI to the router and has Internet connectivity.
|
inline |
Check whether this node is a root node.
|
inline |
Check if sendToInternet() API is enabled
|
inline |
Callback that gets called when bridge status changes.
This fires when a bridge node reports a change in Internet connectivity status. Useful for implementing failover logic or message queueing.
|
inline |
Callback that gets called every time the layout of the mesh changes
|
inline |
|
inline |
Register callback for primary gateway changes
This callback fires when the primary gateway changes, either because a new gateway becomes available, the current gateway becomes unavailable, or a better gateway is discovered.
| callback | Function to call when primary gateway changes |
|
inline |
Set periodic health metrics callback
Registers a callback that will be invoked periodically with current health metrics. Useful for automated monitoring, MQTT publishing, or Prometheus export.
| callback | Function to call with metrics |
| intervalMs | Callback interval in milliseconds (default: 60000 = 60 seconds) |
|
inline |
Register callback for local Internet connectivity changes
This callback fires when THIS node's direct Internet connectivity changes, as detected by the periodic health check.
| callback | Function to call when local Internet status changes |
|
inline |
|
inline |
Callback that gets called when a delay measurement is received.
This fires when a time delay masurement response is received, after a request was sent.
|
inline |
Callback that gets called every time node time gets adjusted
Node time is automatically kept in sync in the mesh. This gets called whenever the time is to far out of sync with the rest of the mesh and gets adjusted.
|
inline |
Set callback for queue state changes
Fires when queue state changes (EMPTY, NORMAL, 75%, FULL)
|
inline |
Set a callback routine for any messages that are addressed to this node.
Every time this node receives a message, this callback routine will the called. “from†is the id of the original sender of the message, and “msg†is a string that contains the message. The message can be anything. A JSON, some other text string, or binary data.
|
inline |
Callback when RTC sync completes
This fires when syncRTCFromNTP() successfully updates the RTC.
|
inline |
Whether this node is being asked to do more than its part can carry.
The ESP8266 is specified for small meshes, or as a leaf in larger ones: measured as an interior node of a seven-node mesh it runs at 10–13 KB free — a working set that tracks its live connections and the traffic through them, not a leak — and a single 8 KB package or one OTA part can then fail to allocate. This is the part's limit, not a defect. It is set by capacityCheck(), which the Arduino layer runs periodically on ESP8266 and which logs an ERROR when the condition is first met and again every five minutes it persists. Configure the node as a leaf with init(..., maxconn = 0) — or 1 to allow a single child.
|
inline |
Number of messages still awaiting delivery acknowledgment
|
inline |
Prune old messages from the queue
| maxAgeMs | Maximum age in milliseconds |
|
inlineprotected |
|
inline |
Queue a message with priority for later manual delivery
Use this to buffer critical messages when your upstream (MQTT/HTTP/etc.) is unavailable. The library does NOT deliver these on its own — your app must call flushMessageQueue() and removeQueuedMessage() once its own connectivity check clears.
| payload | Message content to queue |
| destination | Optional destination metadata (e.g., MQTT topic, HTTP endpoint) |
| priority | Message priority (default: PRIORITY_NORMAL) |
|
inlineprotected |
|
inline |
Remove a successfully sent message from the queue
| messageId | ID of message to remove |
|
inline |
Reset health metrics counters
Resets all counters to zero but keeps current state metrics (RSSI, node count, etc.) Useful for periodic monitoring windows.
|
inline |
Reset Internet health check statistics
|
inline |
Wrapper function for ESP32 semaphore give function
Does nothing on ESP8266 hardware
|
inline |
Wrapper function for ESP32 semaphore function
Waits for the semaphore to be available and then returns true
Always return true on ESP8266
|
inline |
Broadcast a message with per-node delivery confirmation
The set of nodes expected to acknowledge is snapshotted from the current mesh layout (excluding this node) when the broadcast is sent. The callback fires once per expected node: with delivered = true and the round-trip latency when that node's ACK arrives, or with delivered = false when ackTimeoutMs elapses. The local node never acknowledges itself, even with includeSelf = true.
Note: includeSelf and ackCallback are deliberately non-defaulted on this overload; C++ overload resolution against the priority overload would otherwise be ambiguous or, worse, silently convert a lambda to bool.
| msg | The message to broadcast |
| includeSelf | Send message to myself as well. |
| ackCallback | Delivery confirmation callback, fired once per node. Passing nullptr behaves like the plain sendBroadcast(). |
| ackTimeoutMs | How long to wait for acknowledgments (default 5000 ms). Values below 1000 ms are raised to 1000 ms so the 50 ms jitter window still leaves time for routed round-trip delivery. |
|
inline |
Broadcast a message to every node on the mesh network.
| includeSelf | Send message to myself as well. Default is false. |
|
inline |
Broadcast a message to every node — unified path (issue #384)
All sendBroadcast() overloads funnel into this one. Priority and delivery confirmation compose freely; see SendOptions for the semantics of each field. With an ackCallback set, the set of nodes expected to acknowledge is snapshotted from the current mesh layout (excluding this node) when the broadcast is sent, and the callback fires once per expected node. ackTimeoutMs values below 1000 ms are raised to 1000 ms so the 50 ms ACK jitter window still leaves time for routed round-trip delivery.
| msg | The message to broadcast |
| options | Priority and/or delivery confirmation options. |
| includeSelf | Send message to myself as well. Default is false. |
|
inline |
Broadcast a message with priority to every node on the mesh network.
| msg | The message to broadcast |
| priorityLevel | Priority level: 0=CRITICAL, 1=HIGH, 2=NORMAL, 3=LOW |
| includeSelf | Send message to myself as well. Default is false. |
|
inline |
Handle incoming gateway acknowledgment package Answer a gateway request: send its GATEWAY_ACK back to the origin node.
A request this node originated completes locally, without a mesh hop. Otherwise the ack is routed to the origin; when the NodeTree has not yet converged enough for findRoute() to resolve it – a freshly promoted gateway can receive data before that – the connection the request arrived on is a valid reverse path, since every intermediate node routes the addressed ack onward toward the origin.
Used by the gateway's own handler (wifi.hpp) and by the fallback every node registers for requests it cannot serve.
|
inline |
Send message to a specific node
| destId | The nodeId of the node to send it to. |
| msg | The message to send |
|
inline |
Send message to a specific node with delivery confirmation
The message is tagged with a unique id and the destination node automatically replies with an acknowledgment. The callback fires exactly once: with delivered = true and the measured round-trip latency when the ACK arrives, or with delivered = false when ackTimeoutMs elapses without an ACK. ACK processing happens inside mesh.update() — no blocking waits.
| destId | The nodeId of the node to send it to. |
| msg | The message to send |
| ackCallback | Delivery confirmation callback. Passing nullptr behaves exactly like the plain sendSingle(). |
| ackTimeoutMs | How long to wait for the acknowledgment (default 5000 ms). |
|
inline |
Send message to a specific node — unified path (issue #384)
All sendSingle() overloads funnel into this one. Priority and delivery confirmation compose freely; see SendOptions for the semantics of each field.
| destId | The nodeId of the node to send it to. |
| msg | The message to send |
| options | Priority and/or delivery confirmation options. |
|
inline |
Send message to a specific node with priority
| destId | The nodeId of the node to send it to. |
| msg | The message to send |
| priorityLevel | Priority level: 0=CRITICAL, 1=HIGH, 2=NORMAL, 3=LOW |
|
inline |
Send data to an Internet destination, receiving the whole result
The same request as the (success, httpStatus, error) form, but the callback also gets the start of the response body, whether the request may be resent safely, and how many times it was issued. Use it when a service's status alone does not say whether it did what was asked – the sendToInternet example judges CallMeBot's replies this way.
|
inline |
Send data to an Internet destination through the mesh gateway
This method provides a high-level API for sending data to the Internet through the mesh network. It automatically handles:
PRIORITY LEVELS:
CALLBACK BEHAVIOR: The callback is invoked when:
| destination | The Internet destination URL (e.g., "https://api.example.com/data") |
| payload | The data payload to send (typically JSON) |
| callback | Function called with result (success, httpStatus, error) |
| priority | Message priority (0=CRITICAL to 3=LOW, default: 2=NORMAL) |
|
inline |
Set the interval for bridge status broadcasts (bridge nodes only)
| intervalMs | Broadcast interval in milliseconds (default: 30000 = 30 seconds) |
|
inline |
Set the timeout for considering a bridge offline
| timeoutMs | Timeout in milliseconds (default: 60000 = 60 seconds) |
|
inline |
The mesh should contains a root node
This will cause the mesh to restructure more quickly around the root node. Note that this could have adverse effects if set, while there is no root node present. Also see painlessMesh::setRoot().
|
inline |
Change the internal log level
|
inline |
Set Internet check interval
| intervalMs | Interval between checks in milliseconds |
|
inline |
Set custom Internet check target
Override the default check host/port (8.8.8.8:53).
| host | Host to check (IP or hostname) |
| port | Port to connect to (default 53 for DNS) |
|
inline |
Set Internet check timeout
| timeoutMs | Timeout for each check in milliseconds |
|
inline |
Configure Internet request timeout
| timeoutMs | Timeout in milliseconds (default: 30000) |
|
inline |
Configure Internet request retry count
| retryCount | Number of retry attempts (default: 3) |
|
inline |
Configure base retry delay for exponential backoff
| delayMs | Base delay in milliseconds (default: 1000) |
|
inline |
Set the node as an root/master node for the mesh
This is an optional setting that can speed up mesh formation. At most one node in the mesh should be a root, or you could end up with multiple subMeshes.
We recommend any AP_ONLY nodes (e.g. a bridgeNode) to be set as a root node.
If one node is root, then it is also recommended to call painlessMesh::setContainsRoot() on all the nodes in the mesh.
|
inlineprotected |
|
inline |
Configure TCP connection retry behaviour
Lets latency-sensitive, high-reliability or battery-powered deployments pick their own retry envelope. Values outside safe operating bounds are clamped - see painlessmesh::tcp::clampTcpRetryConfig(). Read the applied (post-clamp) values back with getTcpRetryConfig().
The defaults reproduce the previous hardcoded behaviour exactly, so existing sketches that never call this see no change.
| config | Retry parameters to apply |
|
inline |
Set time authority status for this node
Nodes with time authority (RTC or Internet) are preferred as time sources during mesh time synchronization. This prevents nodes from adopting time from nodes without accurate time sources.
This is automatically set to true when:
| hasAuthority | True if node has accurate time source (RTC/Internet) |
|
inline |
Sends a node a packet to measure network trip delay to that node.
After calling this function, user program have to wait to the response in the form of a callback specified by onNodeDelayReceived().
|
inline |
|
inline |
Disconnect and stop this node
|
inline |
Return a json representation of the current mesh layout
|
inline |
Sync RTC from NTP/Internet time source
Should be called when Internet connection is available to update the RTC with accurate time. Typically called in onBridgeStatusChanged callback when Internet becomes available.
| ntpTimestamp | Unix timestamp from NTP source |
|
inline |
Test bridge connectivity
Runs a connectivity test to the primary bridge and optionally to Internet. Measures latency and reachability.
|
inline |
Perform crucial maintenance task
Add this to your loop() function. This routine runs various maintenance tasks.
|
inline |
Update bridge information from received status package Internal method called when bridge status is received
| bridgeNodeId | ID of the bridge node |
| internetConnected | Internet connectivity status |
| routerRSSI | Router signal strength |
| routerChannel | Router WiFi channel |
| uptime | Bridge uptime |
| gatewayIP | Router gateway IP |
| timestamp | Status timestamp |
|
inline |
Can this node serve a gateway request on its own uplink right now?
hasLocalInternet() is the last periodic probe's answer. On a bridge the first probe runs while the station is still associating and fails, and the next is a full interval (30 s) away, so for that whole window a send fell through to the mesh path and was refused for want of a peer (issue #450). When the flag says no and the health check is running, spend the one on-demand probe the checker allows per period: a send made after the uplink came up is then served locally, and a node whose uplink really is down pays one probe per interval, not one per call.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
| uint32_t painlessmesh::Mesh< T >::_capacityWarnedAt = 0 |
| bool painlessmesh::Mesh< T >::_overCapacity = false |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
protected |
|
protected |
| std::shared_ptr<Task> painlessmesh::Mesh< T >::bridgeCleanupTask = nullptr |
| bool painlessmesh::Mesh< T >::bridgeStatusBroadcastEnabled = true |
| bridgeStatusChangedCallback_t painlessmesh::Mesh< T >::bridgeStatusChangedCallback |
| uint32_t painlessmesh::Mesh< T >::bridgeStatusIntervalMs = 30000 |
| uint32_t painlessmesh::Mesh< T >::bridgeTimeoutMs = 60000 |
|
protected |
|
staticconstexpr |
| callback::List<uint32_t> painlessmesh::Mesh< T >::changedConnectionCallbacks |
| bool painlessmesh::Mesh< T >::diagnosticsEnabled = false |
| callback::List<uint32_t, bool> painlessmesh::Mesh< T >::droppedConnectionCallbacks |
| std::vector<ElectionRecord> painlessmesh::Mesh< T >::electionHistory |
|
staticconstexpr |
| gatewayChangedCallback_t painlessmesh::Mesh< T >::gatewayChangedCallback |
| std::shared_ptr<Task> painlessmesh::Mesh< T >::internetCleanupTask = nullptr |
| gateway::InternetHealthChecker painlessmesh::Mesh< T >::internetHealthChecker |
| std::shared_ptr<Task> painlessmesh::Mesh< T >::internetHealthCheckTask = nullptr |
| uint32_t painlessmesh::Mesh< T >::internetRequestTimeout = 30000 |
| uint8_t painlessmesh::Mesh< T >::internetRetryCount = 3 |
| uint32_t painlessmesh::Mesh< T >::internetRetryDelay = 1000 |
| bool painlessmesh::Mesh< T >::isExternalScheduler = false |
| std::vector<BridgeInfo> painlessmesh::Mesh< T >::knownBridges |
| BridgeChangeEvent painlessmesh::Mesh< T >::lastBridgeChange |
| uint32_t painlessmesh::Mesh< T >::lastBridgeChangeTime = 0 |
| localInternetChangedCallback_t painlessmesh::Mesh< T >::localInternetChangedCallback |
|
static |
|
static |
|
staticconstexprprotected |
| MessageQueue* painlessmesh::Mesh< T >::messageQueue = nullptr |
| uint32_t painlessmesh::Mesh< T >::metricsDisconnectCount = 0 |
| Scheduler* painlessmesh::Mesh< T >::mScheduler = nullptr |
| callback::List<uint32_t> painlessmesh::Mesh< T >::newConnectionCallbacks |
| nodeDelayCallback_t painlessmesh::Mesh< T >::nodeDelayReceivedCallback |
| nodeTimeAdjustedCallback_t painlessmesh::Mesh< T >::nodeTimeAdjustedCallback |
|
protected |
| std::map<uint32_t, PendingInternetRequest> painlessmesh::Mesh< T >::pendingInternetRequests |
|
protected |
| rtc::RTCManager painlessmesh::Mesh< T >::rtcManager |
| rtcSyncCompleteCallback_t painlessmesh::Mesh< T >::rtcSyncCompleteCallback |
| bool painlessmesh::Mesh< T >::sendToInternetEnabled = false |
| bool painlessmesh::Mesh< T >::shouldContainRoot = false |
Is the node a root node.
| friend painlessmesh::Mesh< T >::T |
| painlessmesh::tcp::TcpRetryConfig painlessmesh::Mesh< T >::tcpRetryConfig |