mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
basic web config
This commit is contained in:
@@ -19,6 +19,7 @@ class WebConfigPlugin : public Plugin {
|
||||
public:
|
||||
WebConfigPlugin(AsyncWebServer* webServer){
|
||||
server = webServer;
|
||||
server->serveStatic("/config.json", SPIFFS, "config.json");
|
||||
}
|
||||
void activate(Scheduler* userScheduler, Network* network){
|
||||
|
||||
@@ -28,28 +29,20 @@ class WebConfigPlugin : public Plugin {
|
||||
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());
|
||||
server->on("/restart", HTTP_POST, [](AsyncWebServerRequest *request){
|
||||
Serial.println("POST /restart");
|
||||
ESP.restart();
|
||||
});
|
||||
// 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();
|
||||
if(request->hasParam("config", true)) {
|
||||
String inStr = request->getParam("config", true)->value();
|
||||
MeshSprocketConfig config;
|
||||
config.fromJsonString(inStr);
|
||||
Serial.println(config.toJsonString());
|
||||
// config.saveFile("/config.json");
|
||||
config.saveFile("/config.json");
|
||||
}
|
||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||
request->redirect("/");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,6 +25,8 @@ class WebServerPlugin : public Plugin {
|
||||
//connectUpdateNetwork(network);
|
||||
net = static_cast<MeshNet*>(network);
|
||||
server->serveStatic(config.contextPath, SPIFFS, config.docRoot).setDefaultFile(config.defaultFile);
|
||||
// TODO add auth if configured
|
||||
// server->setAuthentication("user", "pass");
|
||||
server->begin();
|
||||
Serial.println("WebServer activated");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user