mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-14 20:56:38 +01:00
basic web config
This commit is contained in:
@@ -1,7 +1,22 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
</head>
|
<head>
|
||||||
<body>
|
<script src="jquery-3.3.1.min.js"></script>
|
||||||
<h1>Sprocket</h1>
|
<script src="script.js"></script>
|
||||||
</body>
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Sprocket Config</h1>
|
||||||
|
|
||||||
|
<button class="js-restart">Restart</button>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<form action="/config" method="post">
|
||||||
|
<textarea name="config" class="js-config" rows="20" cols="50"></textarea>
|
||||||
|
<br>
|
||||||
|
<input type="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
2
data/www/jquery-3.3.1.min.js
vendored
Normal file
2
data/www/jquery-3.3.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
11
data/www/script.js
Normal file
11
data/www/script.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
$(() => {
|
||||||
|
// load config
|
||||||
|
$.get("/config.json", (data) => {
|
||||||
|
$('.js-config').val(JSON.stringify(data, null, 4));
|
||||||
|
});
|
||||||
|
// add handlers
|
||||||
|
$('.js-restart').click(()=>{
|
||||||
|
$.post('/restart');
|
||||||
|
alert('restarting...');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -57,7 +57,7 @@ lib_deps = ${common.lib_deps}
|
|||||||
ArduinoOTA
|
ArduinoOTA
|
||||||
ESP Async WebServer
|
ESP Async WebServer
|
||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
upload_port = 192.168.1.247
|
;upload_port = 192.168.1.247
|
||||||
|
|
||||||
[env:meshMqttBridge]
|
[env:meshMqttBridge]
|
||||||
src_filter = +<*> -<examples/> +<examples/meshMqttBridge/>
|
src_filter = +<*> -<examples/> +<examples/meshMqttBridge/>
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class WebConfigPlugin : public Plugin {
|
|||||||
public:
|
public:
|
||||||
WebConfigPlugin(AsyncWebServer* webServer){
|
WebConfigPlugin(AsyncWebServer* webServer){
|
||||||
server = webServer;
|
server = webServer;
|
||||||
|
server->serveStatic("/config.json", SPIFFS, "config.json");
|
||||||
}
|
}
|
||||||
void activate(Scheduler* userScheduler, Network* network){
|
void activate(Scheduler* userScheduler, Network* network){
|
||||||
|
|
||||||
@@ -28,28 +29,20 @@ class WebConfigPlugin : public Plugin {
|
|||||||
Serial.println("GET /heap");
|
Serial.println("GET /heap");
|
||||||
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
request->send(200, "text/plain", String(ESP.getFreeHeap()));
|
||||||
});
|
});
|
||||||
server->on("/config", HTTP_GET, [](AsyncWebServerRequest *request){
|
server->on("/restart", HTTP_POST, [](AsyncWebServerRequest *request){
|
||||||
Serial.println("GET /config");
|
Serial.println("POST /restart");
|
||||||
|
ESP.restart();
|
||||||
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){
|
server->on("/config", HTTP_POST, [](AsyncWebServerRequest *request){
|
||||||
Serial.println("POST /config");
|
Serial.println("POST /config");
|
||||||
// read existing config
|
if(request->hasParam("config", true)) {
|
||||||
MeshSprocketConfig config;
|
String inStr = request->getParam("config", true)->value();
|
||||||
config.fromFile("/config.json");
|
MeshSprocketConfig config;
|
||||||
if(request->hasParam("mesh", true)) {
|
|
||||||
String inStr = request->getParam("mesh", true)->value();
|
|
||||||
config.fromJsonString(inStr);
|
config.fromJsonString(inStr);
|
||||||
Serial.println(config.toJsonString());
|
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);
|
//connectUpdateNetwork(network);
|
||||||
net = static_cast<MeshNet*>(network);
|
net = static_cast<MeshNet*>(network);
|
||||||
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
|
||||||
|
// server->setAuthentication("user", "pass");
|
||||||
server->begin();
|
server->begin();
|
||||||
Serial.println("WebServer activated");
|
Serial.println("WebServer activated");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user