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>
|
||||
|
||||
<head>
|
||||
<script src="jquery-3.3.1.min.js"></script>
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Sprocket</h1>
|
||||
<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>
|
||||
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
|
||||
ESP Async WebServer
|
||||
ESPAsyncTCP
|
||||
upload_port = 192.168.1.247
|
||||
;upload_port = 192.168.1.247
|
||||
|
||||
[env:meshMqttBridge]
|
||||
src_filter = +<*> -<examples/> +<examples/meshMqttBridge/>
|
||||
|
||||
@@ -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
|
||||
if(request->hasParam("config", true)) {
|
||||
String inStr = request->getParam("config", true)->value();
|
||||
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");
|
||||
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