Serving files from SPIFFS
This commit is contained in:
parent
2ea7220173
commit
15b7838219
@ -19,6 +19,7 @@
|
|||||||
<pathentry include="/home/youen/Arduino/libraries/AsyncTCP/src" kind="inc" path="" system="true"/>
|
<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/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/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="mac" name="ESP32" path="" value=""/>
|
||||||
<pathentry kind="out" path="build"/>
|
<pathentry kind="out" path="build"/>
|
||||||
<pathentry kind="src" path=""/>
|
<pathentry kind="src" path=""/>
|
||||||
|
7
ESP32/data/www/index.html
Normal file
7
ESP32/data/www/index.html
Normal file
@ -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>
|
@ -1,28 +1,23 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include <FS.h>
|
||||||
|
#include <SPIFFS.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
#include "wifi-credentials.h"
|
#include "wifi-credentials.h"
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
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()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
if(!SPIFFS.begin(false)){
|
||||||
|
Serial.println("SPIFFS Mount Failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Connect to Wi-Fi
|
// Connect to Wi-Fi
|
||||||
WiFi.begin(wifi_ssid, wifi_password);
|
WiFi.begin(wifi_ssid, wifi_password);
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
while (WiFi.status() != WL_CONNECTED)
|
||||||
@ -35,10 +30,7 @@ void setup()
|
|||||||
Serial.print("Wifi connected, ip=");
|
Serial.print("Wifi connected, ip=");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html");
|
||||||
{
|
|
||||||
request->send(200, "text/html", index_html);
|
|
||||||
});
|
|
||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
Serial.println("HTTP server started");
|
Serial.println("HTTP server started");
|
||||||
|
Loading…
Reference in New Issue
Block a user