From 15b783821958585d966ae93c229366902cd69190 Mon Sep 17 00:00:00 2001 From: Youen Toupin Date: Sat, 12 Mar 2022 13:07:41 +0100 Subject: [PATCH] Serving files from SPIFFS --- ESP32/.cproject | 1 + ESP32/data/www/index.html | 7 +++++++ ESP32/vehicle-monitor.cpp | 24 ++++++++---------------- 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 ESP32/data/www/index.html diff --git a/ESP32/.cproject b/ESP32/.cproject index 0d4d3cc..3f927c8 100644 --- a/ESP32/.cproject +++ b/ESP32/.cproject @@ -19,6 +19,7 @@ + diff --git a/ESP32/data/www/index.html b/ESP32/data/www/index.html new file mode 100644 index 0000000..beb8acd --- /dev/null +++ b/ESP32/data/www/index.html @@ -0,0 +1,7 @@ + + + ESP Web Server + + +

Hello world! This file is served from the SPIFFS

+ diff --git a/ESP32/vehicle-monitor.cpp b/ESP32/vehicle-monitor.cpp index cf79120..799d27e 100644 --- a/ESP32/vehicle-monitor.cpp +++ b/ESP32/vehicle-monitor.cpp @@ -1,28 +1,23 @@ #include #include +#include +#include #include #include "wifi-credentials.h" AsyncWebServer server(80); -const char index_html[] PROGMEM = R"rawliteral( - - - - ESP Web Server - - -

Hello world!

- - -)rawliteral"; - void setup() { Serial.begin(115200); + if(!SPIFFS.begin(false)){ + Serial.println("SPIFFS Mount Failed"); + return; + } + // Connect to Wi-Fi WiFi.begin(wifi_ssid, wifi_password); while (WiFi.status() != WL_CONNECTED) @@ -35,10 +30,7 @@ void setup() Serial.print("Wifi connected, ip="); Serial.println(WiFi.localIP()); - server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) - { - request->send(200, "text/html", index_html); - }); + server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html"); server.begin(); Serial.println("HTTP server started");