#ifndef __MESHNET_H__ #define __MESHNET_H__ #include #include #include "Network.h" 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 | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION); 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(){ Serial.println("connect station"); mesh.stationManual("tErAx1d", "ramalamadingdong"); mesh.setHostname("MeshNode"); return this; } void broadcast(String msg){ mesh.sendBroadcast(msg); } void update(){ 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); } }; #endif