#ifndef __WEB_CONFIG_PLUGIN_H__ #define __WEB_CONFIG_PLUGIN_H__ #include #include "TaskSchedulerDeclarations.h" #include "ArduinoOTA.h" #include "MeshNet.h" #include "Plugin.h" #include #include 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(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