start a web server on port 80, serving static HTML from SPIFFS

This commit is contained in:
Kevin Matz 2020-12-16 12:46:26 -05:00
parent 1e3a247a4b
commit 811bd445cb

View File

@ -28,8 +28,10 @@
#include <Arduino.h>
#include <WiFi.h>
#include <SPIFFS.h>
#include <ArduinoOSC.h>
#include <NeoPixelBus.h>
#include <ESPAsyncWebServer.h>
#include <Preferences.h>
#include "sacn.h"
#include "strobe_esp32.h"
@ -81,6 +83,7 @@ struct config_ config;
Strobe *strobe;
NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> *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