|
|
. |
|
|
\ No newline at end of file |
|
|
# painlessMesh API
|
|
|
|
|
|
Using painlessMesh is painless!
|
|
|
|
|
|
First include the library and create an painlessMesh object like this…
|
|
|
|
|
|
```
|
|
|
#include <painlessMesh.h>
|
|
|
painlessMesh mesh;
|
|
|
```
|
|
|
|
|
|
## Member Functions
|
|
|
|
|
|
### void painlessMesh::init( String prefix, String password, uint16_t port )
|
|
|
|
|
|
Add this to your setup() function.
|
|
|
Initialize the mesh network. This routine does the following things.
|
|
|
|
|
|
- Starts a wifi network
|
|
|
- Begins searching for other wifi networks that are part of the mesh
|
|
|
- Logs on to the best mesh network node it finds… if it doesn’t find anything, it starts a new search in 5 seconds.
|
|
|
|
|
|
`prefix` = the name of your mesh. The wifi ssid of this node will be prefix + chipId
|
|
|
`password` = wifi password to your mesh
|
|
|
`port` = the TCP port that you want the mesh server to run on
|
|
|
|
|
|
### void painlessMesh::update( void )
|
|
|
|
|
|
Add this to your loop() function
|
|
|
This routine runs various maintainance tasks... Not super interesting, but things don't work without it.
|
|
|
|
|
|
### void painlessMesh::onReceive( &receivedCallback )
|
|
|
|
|
|
Set a callback routine for any messages that are addressed to this node. Callback routine has the following structure.
|
|
|
|
|
|
`void receivedCallback( uint32_t from, String &msg )`
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
### void painlessMesh::onNewConnection( &newConnectionCallback )
|
|
|
|
|
|
This fires every time the local node makes a new connection. The callback has the following structure.
|
|
|
|
|
|
`void newConnectionCallback( uint32_t nodeId )`
|
|
|
|
|
|
`nodeId` is new connected node ID in the mesh.
|
|
|
|
|
|
### void painlessMesh::onChangedConnections( &changedConnectionsCallback )
|
|
|
|
|
|
This fires every time there is a change in mesh topology. Callback has the following structure.
|
|
|
|
|
|
`void onChangedConnections()`
|
|
|
|
|
|
There are no parameters passed. This is a signal only.
|
|
|
|
|
|
### bool painlessMesh::isConnected( nodeId )
|
|
|
|
|
|
Returns if a given node is currently connected to the mesh.
|
|
|
|
|
|
`bool isConnected()`
|
|
|
|
|
|
`nodeId` is node ID that the request refers to.
|
|
|
|
|
|
### void painlessMesh::onNodeTimeAdjusted( &nodeTimeAdjustedCallback )
|
|
|
|
|
|
This fires every time local time is adjusted to synchronize it with mesh time. Callback has the following structure.
|
|
|
|
|
|
`void onNodeTimeAdjusted(int32_t offset)`
|
|
|
|
|
|
`offset` is the adjustment delta that has benn calculated and applied to local clock.
|
|
|
|
|
|
### bool painlessMesh::sendBroadcast( String &msg)
|
|
|
|
|
|
Sends msg to every node on the entire mesh network.
|
|
|
|
|
|
returns true if everything works, false if not. Prints an error message to Serial.print, if there is a failure.
|
|
|
|
|
|
### bool painlessMesh::sendSingle(uint32_t dest, String &msg)
|
|
|
|
|
|
Sends msg to the node with Id == dest.
|
|
|
|
|
|
returns true if everything works, false if not. Prints an error message to Serial.print, if there is a failure.
|
|
|
|
|
|
### uint16_t painlessMesh::connectionCount()
|
|
|
|
|
|
Returns the total number of nodes connected to this mesh.
|
|
|
|
|
|
### String subConnectionJson()
|
|
|
|
|
|
Returns mesh topology in JSON format.
|
|
|
|
|
|
### uint32_t painlessMesh::getNodeId( void )
|
|
|
|
|
|
Return the chipId of the node that we are running on.
|
|
|
|
|
|
### uint32_t painlessMesh::getNodeTime( void )
|
|
|
|
|
|
Returns the mesh timebase microsecond counter. Rolls over 71 minutes from startup of the first node. |
|
|
\ No newline at end of file |