mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-17 21:56:40 +01:00
add sendTo method, cleanup
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <painlessMesh.h>
|
||||
#include <WiFiClient.h>
|
||||
#include "Network.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
@@ -22,59 +23,19 @@ struct MeshConfig {
|
||||
class MeshNet : public Network {
|
||||
public:
|
||||
painlessMesh mesh;
|
||||
|
||||
MeshConfig config;
|
||||
|
||||
MeshNet(MeshConfig cfg) : Network() {
|
||||
config = cfg;
|
||||
}
|
||||
|
||||
Network* init(){
|
||||
|
||||
Serial.println("init mesh");
|
||||
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
|
||||
mesh.setDebugMsgTypes( config.debugTypes );
|
||||
mesh.init( config.meshSSID, config.meshPassword, scheduler, config.meshPort, WIFI_AP_STA, config.channel );
|
||||
|
||||
//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));
|
||||
|
||||
if(config.stationMode){
|
||||
Serial.println("connect station");
|
||||
mesh.stationManual(config.stationSSID, config.stationPassword);
|
||||
mesh.setHostname(config.hostname);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
Network* connect(){
|
||||
return this;
|
||||
}
|
||||
void broadcast(String msg){
|
||||
mesh.sendBroadcast(msg);
|
||||
}
|
||||
void update(){
|
||||
// only needed when no scheduler was passed to mesh.init
|
||||
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) {
|
||||
id = 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);
|
||||
}
|
||||
MeshNet(MeshConfig cfg);
|
||||
Network* init();
|
||||
Network* connect();
|
||||
|
||||
void broadcast(String msg);
|
||||
void sendTo(uint32_t target, String msg);
|
||||
void update(); // only needed when no scheduler was passed to mesh.init
|
||||
void receivedCallback( uint32_t from, String &msg );
|
||||
void newConnectionCallback(uint32_t nodeId);
|
||||
void changedConnectionCallback();
|
||||
void nodeTimeAdjustedCallback(int32_t offset);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user