mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 05:24:30 +01:00
move webserver stuff to plugin
This commit is contained in:
57
src/plugins/WebConfigPlugin.cpp
Normal file
57
src/plugins/WebConfigPlugin.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef __WEB_CONFIG_PLUGIN_H__
|
||||
#define __WEB_CONFIG_PLUGIN_H__
|
||||
|
||||
#include "TaskSchedulerDeclarations.h"
|
||||
#include "ArduinoOTA.h"
|
||||
#include "MeshNet.h"
|
||||
#include "Plugin.h"
|
||||
#include <plugins/WebSO.h>
|
||||
#include <base/MeshSprocketConfig.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
|
||||
class WebConfigPlugin : public Plugin {
|
||||
private:
|
||||
MeshNet* net;
|
||||
AsyncWebServer* server;
|
||||
public:
|
||||
WebConfigPlugin(AsyncWebServer* webServer){
|
||||
server = webServer;
|
||||
}
|
||||
void activate(Scheduler* userScheduler, Network* network){
|
||||
|
||||
net = static_cast<MeshNet*>(network);
|
||||
|
||||
server->on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
Serial.println("GET /heap");
|
||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||
});
|
||||
server->on("/config", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
Serial.println("GET /config");
|
||||
|
||||
MeshSprocketConfig config;
|
||||
config.fromFile("/config.json");
|
||||
config.meshPassword = "";
|
||||
config.stationPassword = "";
|
||||
request->send(200, "text/plain", config.toJsonString());
|
||||
});
|
||||
// TODO needs testing
|
||||
server->on("/config", HTTP_POST, [](AsyncWebServerRequest *request){
|
||||
Serial.println("POST /config");
|
||||
// read existing config
|
||||
MeshSprocketConfig config;
|
||||
config.fromFile("/config.json");
|
||||
if(request->hasParam("mesh", true)) {
|
||||
String inStr = request->getParam("mesh", true)->value();
|
||||
config.fromJsonString(inStr);
|
||||
Serial.println(config.toJsonString());
|
||||
// config.saveFile("/config.json");
|
||||
}
|
||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user