fix basic example

This commit is contained in:
2018-06-09 18:56:59 +02:00
parent c51183b093
commit e9a04ac827
12 changed files with 232 additions and 38 deletions

View File

@@ -0,0 +1,59 @@
#ifndef __MESH_APP__
#define __MESH_APP__
//#include "Sprocket.h"
#include <painlessMesh.h>
#include "App.h"
#define MESH_PREFIX "whateverYouLike"
#define MESH_PASSWORD "somethingSneaky"
#define MESH_PORT 5555
class MeshApp : public App {
public:
Task someTask;
MeshNet* net;
MeshApp() /* App(sprkt) */ {
Serial.println("joo");
}
void activate(Scheduler* scheduler, MeshNet* network) {
Serial.println("activate");
net = network;
Serial.println("join mesh");
/* net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2));
net->mesh.onNewConnection(bind(&MeshApp::newConnectionCallback, this, _1));
net->mesh.onChangedConnections(bind(&MeshApp::changedConnectionCallback, this));
net->mesh.onNodeTimeAdjusted(bind(&MeshApp::nodeTimeAdjustedCallback, this, _1)); */
join();
/* someTask.set(TASK_SECOND * 5, TASK_FOREVER, [this, network](){
Serial.println("task triggered");
String msg = "Hello from node ";
msg += network.mesh.getNodeId();
network.mesh.sendBroadcast( msg );
});
scheduler->addTask(someTask);
someTask.enable(); */
}
void join(){
}
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
}
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}
void changedConnectionCallback() {
Serial.printf("Changed connections %s\n",net->mesh.subConnectionJson().c_str());
}
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", net->mesh.getNodeTime(),offset);
}
};
#endif