mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-17 05:36:39 +01:00
add base MeshSprocket with OTA enabled
This commit is contained in:
46
src/base/MeshSprocket.h
Normal file
46
src/base/MeshSprocket.h
Normal 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
|
||||
Reference in New Issue
Block a user