#ifndef __MESH_APP__ #define __MESH_APP__ #include #include #include using namespace std; using namespace std::placeholders; class MeshApp : public MeshSprocket { public: Task heartbeatTask; MeshApp(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : MeshSprocket(cfg, otaCfg, webCfg) { } Sprocket* activate(Scheduler* scheduler, Network* network) { // call parent method that enables dispatching and plugins MeshSprocket::activate(scheduler, network); // add a task that sends stuff to the mesh heartbeatTask.set(TASK_SECOND * 5, TASK_FOREVER, bind(&MeshApp::heartbeat, this, net)); addTask(heartbeatTask); return this; } using MeshSprocket::activate; void heartbeat(MeshNet* network){ MeshMessage msg; // = { "wirelos", "broadcast", "local", "alive", 0, }; msg.domain = "wirelos"; msg.to = "broadcast"; msg.msg = "alive"; msg.type = MeshMessage::APP; String msgStr = msg.toJsonString(); network->mesh.sendBroadcast(msgStr/* , true */); } void onMessage( uint32_t from, String &msg ) { Serial.printf("MeshApp onMessage: received from %u msg=%s\n", from, msg.c_str()); } }; #endif