#ifndef __MESH_SPROCKET__ #define __MESH_SPROCKET__ #define DEBUG_ESP_OTA #include #include #include #include #include #include #include #include "config.h" using namespace std; using namespace std::placeholders; class MeshSprocket : public Sprocket { public: MeshNet* net; MeshSprocket(SprocketConfig cfg, OtaConfig otaCfg) : Sprocket(cfg) { addPlugin(new OtaTcpPlugin(otaCfg)); } Sprocket* activate(Scheduler* scheduler, Network* network) { Sprocket::activate(scheduler, network); net = static_cast(network); net->onReceive(bind(&MeshSprocket::dispatch,this, _1, _2)); return this; } using Sprocket::activate; virtual void onMessage(uint32_t from, String &msg) { Serial.printf("MeshSprocket onMessage: received from %u msg=%s\n", from, msg.c_str()); }; void dispatch( uint32_t from, String &msg ) { MeshMessage mMsg; if(mMsg.fromJsonString(msg)){ dispatchMessageToPlugins(mMsg); } onMessage(from, msg); } void loop() { net->update(); scheduler.execute(); } }; #endif