mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
fix basic example
This commit is contained in:
@@ -1,10 +1,56 @@
|
||||
#ifndef __MESHNET_H__
|
||||
#define __MESHNET_H__
|
||||
|
||||
#include <painlessMesh.h>
|
||||
|
||||
#include "Network.h"
|
||||
|
||||
class MeshNet : public Network {
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
|
||||
#define MESH_PREFIX "whateverYouLike"
|
||||
#define MESH_PASSWORD "somethingSneaky"
|
||||
#define MESH_PORT 5555
|
||||
|
||||
|
||||
|
||||
class MeshNet : public Network {
|
||||
public:
|
||||
painlessMesh mesh;
|
||||
Network* init(){
|
||||
Serial.println("init mesh");
|
||||
mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION ); // set before init() so that you can see startup messages
|
||||
mesh.init( MESH_PREFIX, MESH_PASSWORD, scheduler, MESH_PORT, WIFI_AP_STA, 11 );
|
||||
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));
|
||||
|
||||
return this;
|
||||
}
|
||||
Network* connect(){
|
||||
return this;
|
||||
}
|
||||
void update(){
|
||||
Serial.println("update mesh");
|
||||
mesh.update();
|
||||
}
|
||||
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",mesh.subConnectionJson().c_str());
|
||||
}
|
||||
|
||||
void nodeTimeAdjustedCallback(int32_t offset) {
|
||||
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user