diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d69347e..4d3bbe9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,7 +35,9 @@ firmware-build: image: python:2.7-stretch script: - pio run -t clean - - pio run + - pio run --environment basic + - pio run --environment mesh + - pio run --environment meshMqttBridge artifacts: paths: - .pioenvs/*/firmware.* diff --git a/.vscode/settings.json b/.vscode/settings.json index 30a0ad1..ba52e2e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -36,6 +36,7 @@ "type_traits": "cpp", "tuple": "cpp", "typeinfo": "cpp", - "utility": "cpp" + "utility": "cpp", + "bitset": "cpp" } } \ No newline at end of file diff --git a/src/MeshNet.cpp b/src/MeshNet.cpp index 92ebfd6..f7a6a5b 100644 --- a/src/MeshNet.cpp +++ b/src/MeshNet.cpp @@ -11,7 +11,6 @@ Network* MeshNet::init(){ 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)); @@ -36,8 +35,8 @@ void MeshNet::update(){ // only needed when no scheduler was passed to mesh.init mesh.update(); } -void MeshNet::receivedCallback( uint32_t from, String &msg ) { - Serial.printf("--> Received from %u msg=%s\n", from, msg.c_str()); +void MeshNet::onReceive( std::function cb) { + mesh.onReceive(cb); } void MeshNet::newConnectionCallback(uint32_t nodeId) { diff --git a/src/MeshNet.h b/src/MeshNet.h index 1275655..1c59eb7 100644 --- a/src/MeshNet.h +++ b/src/MeshNet.h @@ -28,13 +28,13 @@ class MeshNet : public Network { MeshNet(MeshConfig cfg); Network* init(); - 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); + void broadcast(String msg); + void sendTo(uint32_t target, String msg); + void onReceive(std::function); }; #endif \ No newline at end of file diff --git a/src/Network.h b/src/Network.h index e6af301..e9d9632 100644 --- a/src/Network.h +++ b/src/Network.h @@ -4,6 +4,8 @@ #include #include +typedef std::function msgReceived_cb; + class Network { public: uint32_t id = 0; @@ -13,9 +15,9 @@ class Network { virtual Network* init(Scheduler* s) { scheduler = s; return init(); }; virtual Network* connect() { return this; }; virtual void update() {}; - virtual void broadcast(String msg){ - Serial.println("no-broadcast"); - }; + virtual void broadcast(String msg){}; + virtual void sendTo(uint32_t target, String msg) {}; + virtual void onReceive(std::function); Network* setScheduler(Scheduler* s) { scheduler = s; return this; diff --git a/src/examples/mesh/MeshApp.h b/src/examples/mesh/MeshApp.h index 8c8d28c..15df943 100644 --- a/src/examples/mesh/MeshApp.h +++ b/src/examples/mesh/MeshApp.h @@ -15,7 +15,7 @@ class MeshApp : public Sprocket { MeshApp(SprocketConfig cfg) : Sprocket(cfg) {} Sprocket* activate(Scheduler* scheduler, Network* network) { net = static_cast(network); - net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2)); + net->onReceive(bind(&MeshApp::onReceive,this, _1, _2)); // add a task that sends stuff to the mesh someTask.set(TASK_SECOND * 5, TASK_FOREVER, bind(&MeshApp::heartbeat, this, net)); @@ -28,8 +28,8 @@ class MeshApp : public Sprocket { network->broadcast(msg); } - void receivedCallback( uint32_t from, String &msg ) { - Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str()); + void onReceive( uint32_t from, String &msg ) { + Serial.printf("MeshApp: received from %u msg=%s\n", from, msg.c_str()); // 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); diff --git a/src/examples/mesh/config.h b/src/examples/mesh/config.h index 743cae6..391f13b 100644 --- a/src/examples/mesh/config.h +++ b/src/examples/mesh/config.h @@ -13,11 +13,11 @@ #define STATION_MODE 0 #define WIFI_CHANNEL 11 #define MESH_PORT 5555 -#define MESH_PREFIX "WirelosContraption" +#define MESH_PREFIX "whateverYouLike" #define MESH_PASSWORD "somethingSneaky" #define STATION_SSID "Th1ngs4P" #define STATION_PASSWORD "th3r31sn0sp00n" #define HOSTNAME "mesh-node" -#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION +#define MESH_DEBUG_TYPES ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE #endif \ No newline at end of file