mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
remove network from activation phase
This commit is contained in:
@@ -8,8 +8,8 @@
|
|||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; http://docs.platformio.org/page/projectconf.html
|
; http://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
;[platformio]
|
||||||
env_default = mesh
|
;env_default = mesh
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|||||||
@@ -13,30 +13,28 @@ MeshNet::MeshNet(MeshConfig cfg) : Network() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Network* MeshNet::init(){
|
Network* MeshNet::init(){
|
||||||
|
|
||||||
Serial.println("init mesh");
|
Serial.println("init mesh");
|
||||||
config.fromFile("/config.json");
|
config.fromFile("/config.json");
|
||||||
|
|
||||||
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
|
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
|
||||||
mesh.setDebugMsgTypes( config.debugTypes );
|
mesh.setDebugMsgTypes( config.debugTypes );
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
int MeshNet::connect(){
|
||||||
mesh.init( config.meshSSID, config.meshPassword, scheduler, config.meshPort, WIFI_AP_STA, config.channel );
|
mesh.init( config.meshSSID, config.meshPassword, scheduler, config.meshPort, WIFI_AP_STA, config.channel );
|
||||||
|
|
||||||
mesh.onNewConnection(bind(&MeshNet::newConnectionCallback, this, _1));
|
mesh.onNewConnection(bind(&MeshNet::newConnectionCallback, this, _1));
|
||||||
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
|
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
|
||||||
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
|
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
|
||||||
|
if(config.stationMode){
|
||||||
connectStation(config.stationMode);
|
connectStation();
|
||||||
|
}
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
int MeshNet::connectStation(int doConnect) {
|
|
||||||
if(doConnect){
|
int MeshNet::connectStation() {
|
||||||
Serial.println("connect station");
|
Serial.println("connect station");
|
||||||
mesh.stationManual(config.stationSSID, config.stationPassword);
|
mesh.stationManual(config.stationSSID, config.stationPassword);
|
||||||
mesh.setHostname(config.hostname.c_str());
|
mesh.setHostname(config.hostname.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
void MeshNet::sendTo(uint32_t target, String msg){
|
void MeshNet::sendTo(uint32_t target, String msg){
|
||||||
mesh.sendSingle(target, msg);
|
mesh.sendSingle(target, msg);
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ class MeshNet : public Network {
|
|||||||
MeshSprocketConfig config;
|
MeshSprocketConfig config;
|
||||||
MeshNet(MeshConfig cfg);
|
MeshNet(MeshConfig cfg);
|
||||||
Network* init();
|
Network* init();
|
||||||
int connectStation(int);
|
int connect();
|
||||||
|
int connectStation();
|
||||||
void configure(MeshSprocketConfig cfg);
|
void configure(MeshSprocketConfig cfg);
|
||||||
void update();
|
void update();
|
||||||
void newConnectionCallback(uint32_t nodeId);
|
void newConnectionCallback(uint32_t nodeId);
|
||||||
|
|||||||
@@ -9,10 +9,10 @@
|
|||||||
class Plugin {
|
class Plugin {
|
||||||
public:
|
public:
|
||||||
Mediator* mediator;
|
Mediator* mediator;
|
||||||
virtual void activate(Scheduler*, Network*);
|
virtual void activate(Scheduler*);
|
||||||
virtual void enable(){};
|
virtual void enable(){}
|
||||||
virtual void disable(){};
|
virtual void disable(){}
|
||||||
virtual void onMessage(SprocketMessage msg){};
|
virtual void onMessage(SprocketMessage msg){}
|
||||||
Plugin* mediate(Mediator* m) {
|
Plugin* mediate(Mediator* m) {
|
||||||
mediator = m;
|
mediator = m;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ Sprocket* Sprocket::init(SprocketConfig cfg){
|
|||||||
Sprocket* Sprocket::activate() {
|
Sprocket* Sprocket::activate() {
|
||||||
return activate(&scheduler);
|
return activate(&scheduler);
|
||||||
}
|
}
|
||||||
Sprocket* Sprocket::activate(Scheduler* scheduler, Network* network) {
|
Sprocket* Sprocket::activate(Scheduler* scheduler) {
|
||||||
// setup plugins
|
// setup plugins
|
||||||
activatePlugins(scheduler, network);
|
activatePlugins(scheduler);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ Sprocket* Sprocket::join(Network& net){
|
|||||||
//net.onReceive(bind(&Sprocket::dispatch,this, _1, _2));
|
//net.onReceive(bind(&Sprocket::dispatch,this, _1, _2));
|
||||||
net.connect();
|
net.connect();
|
||||||
network = net;
|
network = net;
|
||||||
return activate(&scheduler, &net);
|
return activate(&scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* Sprocket::addTask(Task& tsk){
|
Sprocket* Sprocket::addTask(Task& tsk){
|
||||||
@@ -57,8 +57,8 @@ void Sprocket::addPlugin(Plugin* p){
|
|||||||
plugins.push_back(p);
|
plugins.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprocket::activatePlugins(Scheduler* scheduler, Network* network){
|
void Sprocket::activatePlugins(Scheduler* scheduler){
|
||||||
for(Plugin* p : plugins){
|
for(Plugin* p : plugins){
|
||||||
p->activate(scheduler, network);
|
p->activate(scheduler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,11 @@ class Sprocket : public Mediator {
|
|||||||
Sprocket* addTask(Task&);
|
Sprocket* addTask(Task&);
|
||||||
virtual void loop();
|
virtual void loop();
|
||||||
virtual Sprocket* activate();
|
virtual Sprocket* activate();
|
||||||
virtual Sprocket* activate(Scheduler*) { return this; }
|
virtual Sprocket* activate(Scheduler*);
|
||||||
virtual Sprocket* activate(Scheduler*, Network*);
|
|
||||||
virtual void dispatch( uint32_t from, String &msg );
|
virtual void dispatch( uint32_t from, String &msg );
|
||||||
|
|
||||||
void addPlugin(Plugin* p);
|
void addPlugin(Plugin* p);
|
||||||
void activatePlugins(Scheduler* scheduler, Network* network);
|
void activatePlugins(Scheduler* scheduler);
|
||||||
void dispatchMessageToPlugins(SprocketMessage msg);
|
void dispatchMessageToPlugins(SprocketMessage msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,14 +22,12 @@ Network* WiFiNet::init() {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
int WiFiNet::connect(){
|
int WiFiNet::connect(){
|
||||||
if(config.valid){
|
WiFi.hostname(config.hostname);
|
||||||
WiFi.hostname(config.hostname);
|
Serial.println("Hostname: " + config.hostname);
|
||||||
Serial.println("Hostname: " + config.hostname);
|
if(!connectStation()) {
|
||||||
if(!connectStation()) {
|
createAccessPoint();
|
||||||
createAccessPoint();
|
|
||||||
}
|
|
||||||
startDNS();
|
|
||||||
}
|
}
|
||||||
|
startDNS();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +39,7 @@ int WiFiNet::connectStation(){
|
|||||||
WiFi.begin(config.stationSSID.c_str(), config.stationPassword.c_str());
|
WiFi.begin(config.stationSSID.c_str(), config.stationPassword.c_str());
|
||||||
Serial.println("connect to " + config.stationSSID);
|
Serial.println("connect to " + config.stationSSID);
|
||||||
|
|
||||||
|
// TODO use tasks
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ class MeshSprocket : public Sprocket {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler) {
|
||||||
Sprocket::activate(scheduler, network);
|
Sprocket::activate(scheduler);
|
||||||
net = static_cast<MeshNet*>(network);
|
//net = static_cast<MeshNet*>(network);
|
||||||
net->onReceive(bind(&MeshSprocket::dispatch,this, _1, _2));
|
//net->onReceive(bind(&MeshSprocket::dispatch,this, _1, _2));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
} using Sprocket::activate;
|
} using Sprocket::activate;
|
||||||
@@ -42,7 +42,7 @@ class MeshSprocket : public Sprocket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
net->update();
|
//net->update();
|
||||||
scheduler.execute();
|
scheduler.execute();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
#include <painlessMesh.h>
|
#include <painlessMesh.h>
|
||||||
#include <base/MeshSprocket.h>
|
#include <base/MeshSprocket.h>
|
||||||
#include <MeshNet.h>
|
#include <MeshNet.h>
|
||||||
#include <plugins/WebSO.h>
|
#include <plugins/WebServerConfig.h>
|
||||||
#include <plugins/OtaTcpPlugin.cpp>
|
//#include <plugins/OtaTcpPlugin.cpp>
|
||||||
#include <plugins/WebServerPlugin.cpp>
|
#include <plugins/WebServerPlugin.cpp>
|
||||||
#include <plugins/WebConfigPlugin.cpp>
|
#include <plugins/WebConfigPlugin.cpp>
|
||||||
#include <plugins/MeshManPlugin.cpp>
|
//#include <plugins/MeshManPlugin.cpp>
|
||||||
#include "Mediator.h"
|
#include "Mediator.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -20,17 +20,17 @@ class MeshApp : public MeshSprocket {
|
|||||||
public:
|
public:
|
||||||
Task heartbeatTask;
|
Task heartbeatTask;
|
||||||
|
|
||||||
MeshApp(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : MeshSprocket(cfg) {
|
MeshApp(SprocketConfig cfg, /* OtaConfig otaCfg, */ WebServerConfig webCfg) : MeshSprocket(cfg) {
|
||||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
//addPlugin(new OtaTcpPlugin(otaCfg));
|
||||||
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
||||||
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
||||||
addPlugin(new MeshManPlugin(&WEBSERVER));
|
//addPlugin(new MeshManPlugin(&WEBSERVER));
|
||||||
subscribe("mesh/heartbeat", bind(&MeshApp::messageHandler, this, _1));
|
subscribe("mesh/heartbeat", bind(&MeshApp::messageHandler, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler) {
|
||||||
// call parent method that enables dispatching and plugins
|
// call parent method that enables dispatching and plugins
|
||||||
MeshSprocket::activate(scheduler, network);
|
MeshSprocket::activate(scheduler);
|
||||||
|
|
||||||
// add a task that sends stuff to the mesh
|
// add a task that sends stuff to the mesh
|
||||||
heartbeatTask.set(TASK_SECOND * 5, TASK_FOREVER, bind(&MeshApp::heartbeat, this, net));
|
heartbeatTask.set(TASK_SECOND * 5, TASK_FOREVER, bind(&MeshApp::heartbeat, this, net));
|
||||||
@@ -51,7 +51,7 @@ class MeshApp : public MeshSprocket {
|
|||||||
msg.topic = "mesh/heartbeat";
|
msg.topic = "mesh/heartbeat";
|
||||||
msg.type = SprocketMessage::APP;
|
msg.type = SprocketMessage::APP;
|
||||||
String msgStr = msg.toJsonString();
|
String msgStr = msg.toJsonString();
|
||||||
network->mesh.sendBroadcast(msgStr, true);
|
//network->mesh.sendBroadcast(msgStr, true);
|
||||||
//String mMsg = String("hoi");
|
//String mMsg = String("hoi");
|
||||||
//publish("mediatorMsg", "hi mediator");
|
//publish("mediatorMsg", "hi mediator");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ MeshNet net({
|
|||||||
});
|
});
|
||||||
MeshApp sprocket(
|
MeshApp sprocket(
|
||||||
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
||||||
{ OTA_PORT, OTA_PASSWORD },
|
/* { OTA_PORT, OTA_PASSWORD }, */
|
||||||
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
|
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
#include <TaskScheduler.h>
|
#include <TaskScheduler.h>
|
||||||
#include <Sprocket.h>
|
#include <Sprocket.h>
|
||||||
#include <plugins/WebSO.h>
|
#include <plugins/WebServerConfig.h>
|
||||||
#include <plugins/OtaTcpPlugin.cpp>
|
//#include <plugins/OtaTcpPlugin.cpp>
|
||||||
#include <plugins/WebServerPlugin.cpp>
|
#include <plugins/WebServerPlugin.cpp>
|
||||||
#include <plugins/WebConfigPlugin.cpp>
|
#include <plugins/WebConfigPlugin.cpp>
|
||||||
#include "Mediator.h"
|
#include "Mediator.h"
|
||||||
@@ -19,15 +19,15 @@ class WiFiApp : public Sprocket {
|
|||||||
public:
|
public:
|
||||||
Scheduler* ts;
|
Scheduler* ts;
|
||||||
Task someTask;
|
Task someTask;
|
||||||
WiFiApp(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : Sprocket(cfg) {
|
WiFiApp(SprocketConfig cfg, /* OtaConfig otaCfg, */ WebServerConfig webCfg) : Sprocket(cfg) {
|
||||||
//addPlugin(new OtaTcpPlugin(otaCfg));
|
//addPlugin(new OtaTcpPlugin(otaCfg));
|
||||||
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
||||||
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
||||||
ts = new Scheduler();
|
ts = new Scheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler) {
|
||||||
Sprocket::activate(ts, network);
|
Sprocket::activate(ts);
|
||||||
Serial.println("activate WiFiApp");
|
Serial.println("activate WiFiApp");
|
||||||
// add a task
|
// add a task
|
||||||
someTask.set(TASK_SECOND, TASK_FOREVER, [](){
|
someTask.set(TASK_SECOND, TASK_FOREVER, [](){
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
WiFiNet net(SPROCKET_MODE,STATION_SSID, STATION_PASSWORD,AP_SSID, AP_PASSWORD,HOSTNAME,CONNECT_TIMEOUT);
|
WiFiNet net(SPROCKET_MODE,STATION_SSID, STATION_PASSWORD,AP_SSID, AP_PASSWORD,HOSTNAME,CONNECT_TIMEOUT);
|
||||||
WiFiApp sprocket(
|
WiFiApp sprocket(
|
||||||
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
||||||
{ OTA_PORT, OTA_PASSWORD },
|
/* { OTA_PORT, OTA_PASSWORD }, */
|
||||||
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
|
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "ArduinoOTA.h"
|
#include "ArduinoOTA.h"
|
||||||
#include "MeshNet.h"
|
#include "MeshNet.h"
|
||||||
#include "Plugin.h"
|
#include "Plugin.h"
|
||||||
#include <plugins/WebSO.h>
|
#include <plugins/WebServerConfig.h>
|
||||||
#include <base/MeshSprocketConfig.h>
|
#include <base/MeshSprocketConfig.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
48
src/plugins/MeshNetworkPlugin.cpp
Normal file
48
src/plugins/MeshNetworkPlugin.cpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef __MESH_NETWORK_PLUGIN__
|
||||||
|
#define __MESH_NETWORK_PLUGIN__
|
||||||
|
|
||||||
|
#define _TASK_PRIORITY
|
||||||
|
|
||||||
|
#include "TaskSchedulerDeclarations.h"
|
||||||
|
#include "Plugin.h"
|
||||||
|
#include <Network.h>
|
||||||
|
#include <MeshNet.h>
|
||||||
|
#include "plugins/NetworkPlugin.cpp"
|
||||||
|
#include <base/SprocketMessage.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
class MeshNetworkPlugin : public NetworkPlugin
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Scheduler *meshScheduler;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MeshNetworkPlugin(MeshConfig cfg)
|
||||||
|
{
|
||||||
|
network = new MeshNet(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void activate(Scheduler *userScheduler)
|
||||||
|
{
|
||||||
|
userScheduler->setHighPriorityScheduler(meshScheduler);
|
||||||
|
network->onReceive(bind(&MeshNetworkPlugin::dispatch, this, _1, _2));
|
||||||
|
// TODO base subscribers
|
||||||
|
NetworkPlugin::activate(meshScheduler);
|
||||||
|
}
|
||||||
|
void dispatch(uint32_t from, String &msg)
|
||||||
|
{
|
||||||
|
SprocketMessage sMsg;
|
||||||
|
sMsg.fromJsonString(msg);
|
||||||
|
if (sMsg.valid)
|
||||||
|
{
|
||||||
|
sMsg.from = String(from);
|
||||||
|
publish(sMsg.topic, sMsg.payload);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
publish("mesh/message", msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
28
src/plugins/NetworkPlugin.cpp
Normal file
28
src/plugins/NetworkPlugin.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef __NETWORK_PLUGIN__
|
||||||
|
#define __NETWORK_PLUGIN__
|
||||||
|
|
||||||
|
#include "TaskSchedulerDeclarations.h"
|
||||||
|
#include "Plugin.h"
|
||||||
|
#include "Network.h"
|
||||||
|
|
||||||
|
class NetworkPlugin : public Plugin
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Network *network;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NetworkPlugin() {}
|
||||||
|
NetworkPlugin(Network *net)
|
||||||
|
{
|
||||||
|
network = net;
|
||||||
|
}
|
||||||
|
|
||||||
|
void activate(Scheduler *userScheduler)
|
||||||
|
{
|
||||||
|
Serial.println("join network");
|
||||||
|
network->init(userScheduler);
|
||||||
|
network->connect();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -26,7 +26,7 @@ class OtaTcpPlugin : public Plugin {
|
|||||||
}
|
}
|
||||||
void connectUpdateNetwork() {
|
void connectUpdateNetwork() {
|
||||||
Serial.println("OTA connect to update-network");
|
Serial.println("OTA connect to update-network");
|
||||||
net->connectStation(1);
|
net->connectStation();
|
||||||
}
|
}
|
||||||
void enable() {
|
void enable() {
|
||||||
Serial.println("OTA enable");
|
Serial.println("OTA enable");
|
||||||
@@ -5,7 +5,8 @@
|
|||||||
#include "TaskSchedulerDeclarations.h"
|
#include "TaskSchedulerDeclarations.h"
|
||||||
#include "ArduinoOTA.h"
|
#include "ArduinoOTA.h"
|
||||||
#include "Plugin.h"
|
#include "Plugin.h"
|
||||||
#include <plugins/WebSO.h>
|
#include <plugins/WebServerConfig.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
@@ -19,7 +20,7 @@ class WebConfigPlugin : public Plugin {
|
|||||||
server = webServer;
|
server = webServer;
|
||||||
server->serveStatic("/config.json", SPIFFS, "config.json");
|
server->serveStatic("/config.json", SPIFFS, "config.json");
|
||||||
}
|
}
|
||||||
void activate(Scheduler* userScheduler, Network* network){
|
void activate(Scheduler* userScheduler){
|
||||||
server->on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){
|
server->on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
Serial.println("GET /heap");
|
Serial.println("GET /heap");
|
||||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
#ifndef __SHARED_PLUGINS__
|
#ifndef __WEB_SERVER_CONFIG__
|
||||||
#define __SHARED_PLUGINS__
|
#define __WEB_SERVER_CONFIG__
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
|
||||||
extern AsyncWebServer WEBSERVER;
|
|
||||||
|
|
||||||
struct WebServerConfig {
|
struct WebServerConfig {
|
||||||
const char* contextPath;
|
const char* contextPath;
|
||||||
@@ -2,9 +2,10 @@
|
|||||||
#define __WEB_SERVER_PLUGIN__
|
#define __WEB_SERVER_PLUGIN__
|
||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
#include "TaskSchedulerDeclarations.h"
|
#include "TaskSchedulerDeclarations.h"
|
||||||
#include "Plugin.h"
|
#include "Plugin.h"
|
||||||
#include <plugins/WebSO.h>
|
#include <plugins/WebServerConfig.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
@@ -18,7 +19,7 @@ class WebServerPlugin : public Plugin {
|
|||||||
config = cfg;
|
config = cfg;
|
||||||
server = webServer;
|
server = webServer;
|
||||||
}
|
}
|
||||||
void activate(Scheduler* userScheduler, Network* network){
|
void activate(Scheduler* userScheduler){
|
||||||
server->serveStatic(config.contextPath, SPIFFS, config.docRoot).setDefaultFile(config.defaultFile);
|
server->serveStatic(config.contextPath, SPIFFS, config.docRoot).setDefaultFile(config.defaultFile);
|
||||||
// TODO add auth if configured
|
// TODO add auth if configured
|
||||||
// server->setAuthentication("user", "pass");
|
// server->setAuthentication("user", "pass");
|
||||||
|
|||||||
Reference in New Issue
Block a user