mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 13:08:21 +01:00
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
#ifndef __WEB_CONFIG_PLUGIN_H__
|
|
#define __WEB_CONFIG_PLUGIN_H__
|
|
|
|
#include <FS.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;
|
|
server->serveStatic("/config.json", SPIFFS, "config.json");
|
|
}
|
|
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("/restart", HTTP_POST, [](AsyncWebServerRequest *request){
|
|
Serial.println("POST /restart");
|
|
ESP.restart();
|
|
});
|
|
server->on("/config", HTTP_POST, [](AsyncWebServerRequest *request){
|
|
Serial.println("POST /config");
|
|
if(request->hasParam("config", true) && request->hasParam("fileName", true)) {
|
|
String inStr = request->getParam("config", true)->value();
|
|
String fileName = request->getParam("fileName", true)->value();
|
|
if (!f) {
|
|
Serial.println("file open for write failed");
|
|
}
|
|
Serial.println("====== Writing to SPIFFS file =========");
|
|
f.print(inStr);
|
|
f.close();
|
|
}
|
|
request->redirect("/");
|
|
});
|
|
}
|
|
};
|
|
|
|
#endif |