basic mesh node example app

This commit is contained in:
2018-06-10 17:56:28 +02:00
parent e9a04ac827
commit 0e6d7f7f3d
12 changed files with 78 additions and 63 deletions

View File

@@ -20,9 +20,10 @@ class MeshNet : public Network {
painlessMesh mesh;
Network* init(){
Serial.println("init mesh");
mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION ); // set before init() so that you can see startup messages
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes( ERROR | STARTUP);
mesh.init( MESH_PREFIX, MESH_PASSWORD, scheduler, MESH_PORT, WIFI_AP_STA, 11 );
mesh.onReceive(bind(&MeshNet::receivedCallback,this, _1, _2));
//mesh.onReceive(bind(&MeshNet::receivedCallback,this, _1, _2));
mesh.onNewConnection(bind(&MeshNet::newConnectionCallback, this, _1));
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
@@ -32,8 +33,10 @@ class MeshNet : public Network {
Network* connect(){
return this;
}
void broadcast(String msg){
mesh.sendBroadcast(msg);
}
void update(){
Serial.println("update mesh");
mesh.update();
}
void receivedCallback( uint32_t from, String &msg ) {
@@ -41,6 +44,7 @@ class MeshNet : public Network {
}
void newConnectionCallback(uint32_t nodeId) {
id = nodeId;
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}