mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-17 21:56:40 +01:00
move webserver stuff to plugin
This commit is contained in:
45
src/examples/mesh/MeshApp.h
Normal file
45
src/examples/mesh/MeshApp.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef __MESH_APP__
|
||||
#define __MESH_APP__
|
||||
|
||||
#include <painlessMesh.h>
|
||||
#include <base/MeshSprocket.h>
|
||||
#include <MeshNet.h>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user