Browse Source

Serving files from SPIFFS

master
Youen Toupin 3 years ago
parent
commit
15b7838219
  1. 1
      ESP32/.cproject
  2. 7
      ESP32/data/www/index.html
  3. 24
      ESP32/vehicle-monitor.cpp

1
ESP32/.cproject

@ -19,6 +19,7 @@
<pathentry include="/home/youen/Arduino/libraries/AsyncTCP/src" kind="inc" path="" system="true"/>
<pathentry include="/home/youen/Arduino/libraries/ESPAsyncWebServer/src" kind="inc" path="" system="true"/>
<pathentry include="/home/youen/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/FS/src" kind="inc" path="" system="true"/>
<pathentry include="/home/youen/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/SPIFFS/src" kind="inc" path="" system="true"/>
<pathentry kind="mac" name="ESP32" path="" value=""/>
<pathentry kind="out" path="build"/>
<pathentry kind="src" path=""/>

7
ESP32/data/www/index.html

@ -0,0 +1,7 @@
<!DOCTYPE HTML>
<head>
<title>ESP Web Server</title>
</head>
<body>
<p>Hello world! This file is served from the SPIFFS</p>
</body>

24
ESP32/vehicle-monitor.cpp

@ -1,28 +1,23 @@
#include <Arduino.h>
#include <WiFi.h>
#include <FS.h>
#include <SPIFFS.h>
#include <ESPAsyncWebServer.h>
#include "wifi-credentials.h"
AsyncWebServer server(80);
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML>
<html>
<head>
<title>ESP Web Server</title>
</head>
<body>
<p>Hello world!</p>
</body>
</html>
)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");

Loading…
Cancel
Save