mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
basic mesh node example app
This commit is contained in:
@@ -1,58 +1,40 @@
|
||||
#ifndef __MESH_APP__
|
||||
#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
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
class MeshApp : public App {
|
||||
public:
|
||||
Task someTask;
|
||||
MeshNet* net;
|
||||
MeshApp() /* App(sprkt) */ {
|
||||
Serial.println("joo");
|
||||
MeshApp() /* : App(sprkt) */ {
|
||||
}
|
||||
void advertise(MeshNet* network){
|
||||
String msg = "Hi, my name is " + String(network->id);
|
||||
network->broadcast(msg);
|
||||
}
|
||||
void activate(Scheduler* scheduler, Network* network) {
|
||||
net = static_cast<MeshNet*>(network);
|
||||
someTask.set(TASK_SECOND * 5, TASK_FOREVER,
|
||||
bind(&MeshApp::advertise, this, net));
|
||||
net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2));
|
||||
scheduler->addTask(someTask);
|
||||
someTask.enable();
|
||||
}
|
||||
|
||||
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);
|
||||
// respond in receive callback can cause an endless loop when all nodes run the same firmware
|
||||
//String foo = String("cheerz back to ") + String(from);
|
||||
//net->broadcast(foo);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user