Files
sprocket-core/src/base/MeshSprocket.h

50 lines
1.3 KiB
C++

#ifndef __MESH_SPROCKET__
#define __MESH_SPROCKET__
#define DEBUG_ESP_OTA
#include <vector>
#include <painlessMesh.h>
#include <Sprocket.h>
#include <MeshNet.h>
#include <base/MeshMessage.h>
#include <base/MeshSprocketConfig.h>
#include <plugins/OtaTcpPlugin.cpp>
#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<MeshNet*>(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