painlessMesh
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
painlessmesh::Mesh< T > Class Template Reference

#include <mesh.hpp>

Inheritance diagram for painlessmesh::Mesh< T >:
Inheritance graph
[legend]
Collaboration diagram for painlessmesh::Mesh< T >:
Collaboration graph
[legend]

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 sendBroadcast (TSTRING msg, bool 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)
 
bool isConnected (uint32_t nodeId)
 
std::list< uint32_t > getNodeList (bool includeSelf=false)
 
TSTRING subConnectionJson (bool pretty=false)
 
std::shared_ptr< Task > addTask (unsigned long aInterval, long aIterations, std::function< void()> aCallback)
 
std::shared_ptr< Task > addTask (std::function< void()> aCallback)
 
 ~Mesh ()
 
- Public Member Functions inherited from painlessmesh::ntp::MeshTime
uint32_t getNodeTime ()
 
- Public Member Functions inherited from painlessmesh::plugin::PackageHandler< T >
void stop ()
 
 ~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 ()
 
protocol::NodeTree asNodeTree ()
 

Protected Member Functions

void setScheduler (Scheduler *baseScheduler)
 
void startTimeSync (std::shared_ptr< T > conn)
 
bool closeConnectionSTA ()
 
void eraseClosedConnections ()
 
bool semaphoreTake ()
 
void semaphoreGive ()
 

Protected Attributes

callback::List< uint32_t > newConnectionCallbacks
 
callback::List< uint32_t, bool > droppedConnectionCallbacks
 
callback::List< uint32_t > changedConnectionCallbacks
 
nodeTimeAdjustedCallback_t nodeTimeAdjustedCallback
 
nodeDelayCallback_t nodeDelayReceivedCallback
 
bool isExternalScheduler = false
 
bool shouldContainRoot
 Is the node a root node. More...
 
Scheduler * mScheduler
 
friend T
 
- Protected Attributes inherited from painlessmesh::ntp::MeshTime
uint32_t timeOffset = 0
 
- Protected Attributes inherited from painlessmesh::plugin::PackageHandler< T >
callback::MeshPackageCallbackList< T > callbackList
 
std::list< std::shared_ptr< Task > > taskList = {}
 
- Protected Attributes inherited from painlessmesh::layout::Layout< T >
uint32_t nodeId = 0
 
bool root = false
 

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 &)
 

Additional Inherited Members

- Public Attributes inherited from painlessmesh::layout::Layout< T >
size_t stability = 0
 
std::list< std::shared_ptr< T > > subs
 

Detailed Description

template<class T>
class painlessmesh::Mesh< T >

Main api class for the mesh

Brings all the functions together except for the WiFi functions

Constructor & Destructor Documentation

◆ ~Mesh()

template<class T>
painlessmesh::Mesh< T >::~Mesh ( )
inline

Member Function Documentation

◆ addTask() [1/2]

template<class T>
std::shared_ptr<Task> painlessmesh::Mesh< T >::addTask ( unsigned long  aInterval,
long  aIterations,
std::function< void()>  aCallback 
)
inline

◆ addTask() [2/2]

template<class T>
std::shared_ptr<Task> painlessmesh::Mesh< T >::addTask ( std::function< void()>  aCallback)
inline

◆ closeConnectionSTA()

template<class T>
bool painlessmesh::Mesh< T >::closeConnectionSTA ( )
inlineprotected

◆ eraseClosedConnections()

template<class T>
void painlessmesh::Mesh< T >::eraseClosedConnections ( )
inlineprotected

◆ getNodeList()

template<class T>
std::list<uint32_t> painlessmesh::Mesh< T >::getNodeList ( bool  includeSelf = false)
inline

Get a list of all known nodes.

This includes nodes that are both directly and indirectly connected to the current node.

◆ init() [1/2]

template<class T>
void painlessmesh::Mesh< T >::init ( uint32_t  id)
inline

◆ init() [2/2]

template<class T>
void painlessmesh::Mesh< T >::init ( Scheduler *  scheduler,
uint32_t  id 
)
inline

◆ isConnected()

template<class T>
bool painlessmesh::Mesh< T >::isConnected ( uint32_t  nodeId)
inline

Are we connected/know a route to the given node?

Parameters
nodeIdThe nodeId we are looking for

◆ isRoot()

template<class T>
bool painlessmesh::Mesh< T >::isRoot ( )
inline

Check whether this node is a root node.

◆ onChangedConnections()

template<class T>
void painlessmesh::Mesh< T >::onChangedConnections ( changedConnectionsCallback_t  onChangedConnections)
inline

Callback that gets called every time the layout of the mesh changes

mesh.onChangedConnections([]() {
// Do something with the event
});

◆ onDroppedConnection()

template<class T>
void painlessmesh::Mesh< T >::onDroppedConnection ( droppedConnectionCallback_t  onDroppedConnection)
inline

Callback that gets called every time the local node drops a connection.

mesh.onDroppedConnection([](auto nodeId) {
// Do something with the event
Serial.println(String(nodeId));
});

◆ onNewConnection()

template<class T>
void painlessmesh::Mesh< T >::onNewConnection ( newConnectionCallback_t  onNewConnection)
inline

Callback that gets called every time the local node makes a new connection.

mesh.onNewConnection([](auto nodeId) {
// Do something with the event
Serial.println(String(nodeId));
});

◆ onNodeDelayReceived()

template<class T>
void painlessmesh::Mesh< T >::onNodeDelayReceived ( nodeDelayCallback_t  onDelayReceived)
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.

mesh.onNodeDelayReceived([](auto nodeId, auto delay) {
// Do something with the event
Serial.println(String(delay));
});

◆ onNodeTimeAdjusted()

template<class T>
void painlessmesh::Mesh< T >::onNodeTimeAdjusted ( nodeTimeAdjustedCallback_t  onTimeAdjusted)
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.

mesh.onNodeTimeAdjusted([](auto offset) {
// Do something with the event
Serial.println(String(offset));
});

◆ onReceive()

template<class T>
void painlessmesh::Mesh< T >::onReceive ( receivedCallback_t  onReceive)
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.

mesh.onReceive([](auto nodeId, auto msg) {
// Do something with the message
Serial.println(msg);
});

◆ semaphoreGive()

template<class T>
void painlessmesh::Mesh< T >::semaphoreGive ( )
inlineprotected

Wrapper function for ESP32 semaphore give function

Does nothing on ESP8266 hardware

◆ semaphoreTake()

template<class T>
bool painlessmesh::Mesh< T >::semaphoreTake ( )
inlineprotected

Wrapper function for ESP32 semaphore function

Waits for the semaphore to be available and then returns true

Always return true on ESP8266

◆ sendBroadcast()

template<class T>
bool painlessmesh::Mesh< T >::sendBroadcast ( TSTRING  msg,
bool  includeSelf = false 
)
inline

Broadcast a message to every node on the mesh network.

Parameters
includeSelfSend message to myself as well. Default is false.
Returns
true if everything works, false if not

◆ sendSingle()

template<class T>
bool painlessmesh::Mesh< T >::sendSingle ( uint32_t  destId,
TSTRING  msg 
)
inline

Send message to a specific node

Parameters
destIdThe nodeId of the node to send it to.
msgThe message to send
Returns
true if everything works, false if not.

◆ setContainsRoot()

template<class T>
void painlessmesh::Mesh< T >::setContainsRoot ( bool  on = true)
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().

◆ setDebugMsgTypes()

template<class T>
void painlessmesh::Mesh< T >::setDebugMsgTypes ( uint16_t  types)
inline

◆ setRoot()

template<class T>
void painlessmesh::Mesh< T >::setRoot ( bool  on = true)
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.

◆ setScheduler()

template<class T>
void painlessmesh::Mesh< T >::setScheduler ( Scheduler *  baseScheduler)
inlineprotected

◆ startDelayMeas()

template<class T>
bool painlessmesh::Mesh< T >::startDelayMeas ( uint32_t  id)
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().

Returns
true if nodeId is connected to the mesh, false otherwise

◆ startTimeSync()

template<class T>
void painlessmesh::Mesh< T >::startTimeSync ( std::shared_ptr< T conn)
inlineprotected

◆ stop()

template<class T>
void painlessmesh::Mesh< T >::stop ( )
inline

Disconnect and stop this node

◆ subConnectionJson()

template<class T>
TSTRING painlessmesh::Mesh< T >::subConnectionJson ( bool  pretty = false)
inline

Return a json representation of the current mesh layout

◆ update()

template<class T>
void painlessmesh::Mesh< T >::update ( void  )
inline

Perform crucial maintenance task

Add this to your loop() function. This routine runs various maintenance tasks.

Friends And Related Function Documentation

◆ meshRecvCb

template<class T>
void meshRecvCb ( void *  ,
AsyncClient ,
void *  ,
size_t   
)
friend

◆ onDataCb

template<class T>
void onDataCb ( void *  ,
AsyncClient ,
void *  ,
size_t   
)
friend

◆ painlessmesh::ntp::handleTimeDelay

template<class T>
void painlessmesh::ntp::handleTimeDelay ( Mesh< T > &  ,
painlessmesh::protocol::TimeDelay  ,
std::shared_ptr< T ,
uint32_t   
)
friend

◆ painlessmesh::ntp::handleTimeSync

template<class T>
void painlessmesh::ntp::handleTimeSync ( Mesh< T > &  ,
painlessmesh::protocol::TimeSync  ,
std::shared_ptr< T ,
uint32_t   
)
friend

◆ painlessmesh::router::handleNodeSync

template<class T>
void painlessmesh::router::handleNodeSync ( Mesh< T > &  ,
protocol::NodeTree  ,
std::shared_ptr< T conn 
)
friend

◆ painlessmesh::tcp::connect

template<class T>
void painlessmesh::tcp::connect ( AsyncClient ,
IPAddress  ,
uint16_t  ,
Mesh< T > &   
)
friend

◆ painlessmesh::tcp::initServer

template<class T>
void painlessmesh::tcp::initServer ( AsyncServer ,
Mesh< T > &   
)
friend

◆ tcpSentCb

template<class T>
void tcpSentCb ( void *  ,
AsyncClient ,
size_t  ,
uint32_t   
)
friend

Member Data Documentation

◆ changedConnectionCallbacks

template<class T>
callback::List<uint32_t> painlessmesh::Mesh< T >::changedConnectionCallbacks
protected

◆ droppedConnectionCallbacks

template<class T>
callback::List<uint32_t, bool> painlessmesh::Mesh< T >::droppedConnectionCallbacks
protected

◆ isExternalScheduler

template<class T>
bool painlessmesh::Mesh< T >::isExternalScheduler = false
protected

◆ mScheduler

template<class T>
Scheduler* painlessmesh::Mesh< T >::mScheduler
protected

◆ newConnectionCallbacks

template<class T>
callback::List<uint32_t> painlessmesh::Mesh< T >::newConnectionCallbacks
protected

◆ nodeDelayReceivedCallback

template<class T>
nodeDelayCallback_t painlessmesh::Mesh< T >::nodeDelayReceivedCallback
protected

◆ nodeTimeAdjustedCallback

template<class T>
nodeTimeAdjustedCallback_t painlessmesh::Mesh< T >::nodeTimeAdjustedCallback
protected

◆ shouldContainRoot

template<class T>
bool painlessmesh::Mesh< T >::shouldContainRoot
protected

Is the node a root node.

◆ T

template<class T>
friend painlessmesh::Mesh< T >::T
protected

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