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

50 lines
1.2 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/SprocketMessage.h>
#include <base/MeshSprocketConfig.h>
#include "config.h"
#include "utils_print.h"
using namespace std;
using namespace std::placeholders;
class MeshSprocket : public Sprocket {
public:
MeshNet* net;
MeshSprocket(){};
MeshSprocket(SprocketConfig cfg) : Sprocket(cfg) {
}
Sprocket* activate(Scheduler* scheduler) {
Sprocket::activate(scheduler);
//net = static_cast<MeshNet*>(network);
//net->onReceive(bind(&MeshSprocket::dispatch,this, _1, _2));
return this;
} using Sprocket::activate;
// TODO transmit SprocketMessage
virtual void dispatch( uint32_t from, String &msg ) {
SprocketMessage sMsg;
sMsg.fromJsonString(msg);
if(sMsg.valid){
sMsg.from = from;
publish(sMsg.topic, sMsg.payload);
}
}
void loop() {
//net->update();
scheduler.execute();
}
};
#endif