add base MeshSprocket with OTA enabled

This commit is contained in:
2018-08-17 14:29:18 +02:00
parent a94aaa6804
commit c127346394
8 changed files with 85 additions and 49 deletions

46
src/base/MeshSprocket.h Normal file
View File

@@ -0,0 +1,46 @@
#ifndef __MESH_SPROCKET__
#define __MESH_SPROCKET__
#define DEBUG_ESP_OTA
#include <painlessMesh.h>
#include <Sprocket.h>
#include <MeshNet.h>
#include <plugins/OtaTcpPlugin.cpp>
#include "config.h"
using namespace std;
using namespace std::placeholders;
class MeshSprocket : public Sprocket {
public:
MeshNet* net;
OtaTcpPlugin* ota;
MeshSprocket(SprocketConfig cfg, OtaConfig otaCfg) : Sprocket(cfg) {
ota = new OtaTcpPlugin(otaCfg);
}
Sprocket* activate(Scheduler* scheduler, Network* network) {
net = static_cast<MeshNet*>(network);
net->onReceive(bind(&MeshSprocket::dispatch,this, _1, _2));
// enable plugins
ota->enable(scheduler, network);
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 ) {
// TODO handle OTA before passing to onMessage
onMessage(from, msg);
}
void loop() {
net->update();
scheduler.execute();
}
};
#endif