From 811bd445cb05b3b88099ff7d0074eaa9fbbccbf7 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Wed, 16 Dec 2020 12:46:26 -0500 Subject: [PATCH] start a web server on port 80, serving static HTML from SPIFFS --- wiflash_esp32/wiflash_esp32.ino | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wiflash_esp32/wiflash_esp32.ino b/wiflash_esp32/wiflash_esp32.ino index d36aba1..06e1e2d 100644 --- a/wiflash_esp32/wiflash_esp32.ino +++ b/wiflash_esp32/wiflash_esp32.ino @@ -28,8 +28,10 @@ #include #include +#include #include #include +#include #include #include "sacn.h" #include "strobe_esp32.h" @@ -81,6 +83,7 @@ struct config_ config; Strobe *strobe; NeoPixelBus *strip; ESPAsyncE131 *e131 = new ESPAsyncE131(); +AsyncWebServer server(80); Preferences prefs; //// static hardware @@ -161,6 +164,18 @@ bool loadConfig() { return true; } + +/* + Start the async web server +*/ +void startHTTPD() { + server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html"); + + server.onNotFound([](AsyncWebServerRequest * request) { + request->send(404, "text/plain", "Not found"); + }); + + server.begin(); } @@ -204,6 +219,12 @@ void setup() { Serial.println("Disabling Bluetooth."); btStop(); + Serial.println("Mounting SPI Flash FS."); + SPIFFS.begin(); + + Serial.println("Starting HTTP interface."); + startHTTPD(); + //// start fixtures hardware: // battery monitor