mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-03-30 17:02:12 +02:00
async server introduction
This commit is contained in:
parent
984a2106f3
commit
f83c408fe7
4 changed files with 58 additions and 9 deletions
|
|
@ -133,12 +133,12 @@ def minify_svg(text: str) -> str:
|
||||||
|
|
||||||
|
|
||||||
MINIFIERS = {
|
MINIFIERS = {
|
||||||
".html": minify_html,
|
# ".html": minify_html,
|
||||||
".htm": minify_html,
|
# ".htm": minify_html,
|
||||||
".css": minify_css,
|
# ".css": minify_css,
|
||||||
# ".js": minify_js,
|
# ".js": minify_js,
|
||||||
# ".json": minify_json,
|
# ".json": minify_json,
|
||||||
".svg": minify_svg,
|
# ".svg": minify_svg,
|
||||||
# ".xml": minify_svg, # same approach works for generic XML
|
# ".xml": minify_svg, # same approach works for generic XML
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,9 @@ lib_deps =
|
||||||
links2004/WebSockets@^2.7.3
|
links2004/WebSockets@^2.7.3
|
||||||
lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7
|
lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
|
esp32async/ESPAsyncWebServer @ ^3.10.3
|
||||||
extra_scripts = pre:minify.py
|
extra_scripts = pre:minify.py
|
||||||
board_build.partitions = min_spiffs.csv
|
board_build.partitions = huge_app.csv
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
build_flags =
|
build_flags =
|
||||||
-DCONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=1
|
-DCONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=1
|
||||||
|
|
@ -47,7 +48,7 @@ lib_deps =
|
||||||
lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7
|
lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
extra_scripts = pre:minify.py
|
extra_scripts = pre:minify.py
|
||||||
board_build.partitions = min_spiffs.csv
|
board_build.partitions = huge_app.csv
|
||||||
board_build.filesystem = littlefs
|
board_build.filesystem = littlefs
|
||||||
|
|
||||||
[env:esp32c3dev]
|
[env:esp32c3dev]
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,41 @@ GitUpdater git;
|
||||||
|
|
||||||
uint32_t oldheap = 0;
|
uint32_t oldheap = 0;
|
||||||
|
|
||||||
|
void listDir(const char *dirname, uint8_t levels) {
|
||||||
|
Serial.printf("Listing: %s\n", dirname);
|
||||||
|
File root = LittleFS.open(dirname);
|
||||||
|
if (!root || !root.isDirectory()) {
|
||||||
|
Serial.println("Failed to open directory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File file = root.openNextFile();
|
||||||
|
while (file) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
Serial.printf(" DIR : %s\n", file.name());
|
||||||
|
if (levels) listDir(file.path(), levels - 1);
|
||||||
|
} else {
|
||||||
|
Serial.printf(" FILE: %-30s %d bytes\n", file.name(), file.size());
|
||||||
|
}
|
||||||
|
file = root.openNextFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
log_i("Startup/Boot....");
|
Serial.println("Startup/Boot....");
|
||||||
log_i("Mounting File System...");
|
Serial.println("Mounting File System...");
|
||||||
|
|
||||||
|
|
||||||
|
if (LittleFS.begin()) {
|
||||||
|
Serial.printf("\nTotal: %d bytes\n", LittleFS.totalBytes());
|
||||||
|
Serial.printf("Used: %d bytes\n", LittleFS.usedBytes());
|
||||||
|
Serial.printf("Free: %d bytes\n", LittleFS.totalBytes() - LittleFS.usedBytes());
|
||||||
|
Serial.println();
|
||||||
|
listDir("/", 3);
|
||||||
|
} else {
|
||||||
|
Serial.println("LittleFS mount failed!");
|
||||||
|
}
|
||||||
|
|
||||||
if(LittleFS.begin()) Serial.println("File system mounted successfully");
|
if(LittleFS.begin()) Serial.println("File system mounted successfully");
|
||||||
else Serial.println("Error mounting file system");
|
else Serial.println("Error mounting file system");
|
||||||
|
|
|
||||||
18
src/Web.cpp
18
src/Web.cpp
|
|
@ -14,6 +14,8 @@
|
||||||
#include "MQTT.h"
|
#include "MQTT.h"
|
||||||
#include "GitOTA.h"
|
#include "GitOTA.h"
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
extern ConfigSettings settings;
|
extern ConfigSettings settings;
|
||||||
extern SSDPClass SSDP;
|
extern SSDPClass SSDP;
|
||||||
|
|
@ -40,8 +42,24 @@ static const char _encoding_json[] = "application/json";
|
||||||
|
|
||||||
WebServer apiServer(8081);
|
WebServer apiServer(8081);
|
||||||
WebServer server(80);
|
WebServer server(80);
|
||||||
|
AsyncWebServer aserver(81);
|
||||||
void Web::startup() {
|
void Web::startup() {
|
||||||
Serial.println("Launching web server...");
|
Serial.println("Launching web server...");
|
||||||
|
aserver.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
|
||||||
|
|
||||||
|
aserver.on("/loginContext", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
|
AsyncJsonResponse *response = new AsyncJsonResponse();
|
||||||
|
JsonObject root = response->getRoot().to<JsonObject>();
|
||||||
|
root["type"] = static_cast<uint8_t>(settings.Security.type);
|
||||||
|
root["permissions"] = settings.Security.permissions;
|
||||||
|
root["serverId"] = settings.serverId;
|
||||||
|
root["version"] = settings.fwVersion.name;
|
||||||
|
root["model"] = "ESPSomfyRTS";
|
||||||
|
root["hostname"] = settings.hostname;
|
||||||
|
response->setLength();
|
||||||
|
request->send(response);
|
||||||
|
});
|
||||||
|
aserver.begin();
|
||||||
}
|
}
|
||||||
void Web::loop() {
|
void Web::loop() {
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue