-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebserver.ino
More file actions
61 lines (50 loc) · 1.58 KB
/
webserver.ino
File metadata and controls
61 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Load Wi-Fi library
#include <WiFi.h>
#include "LittleFS.h"
#include <ESPAsyncWebServer.h>
// Replace with your network credentials
const char *ssid = "feather32";
const char *password = "feather32";
// Set web server port number to 80
AsyncWebServer server(80);
void setup()
{
Serial.begin(115200);
if (!LittleFS.begin())
{
Serial.println("An Error has occurred while mounting LittleFS");
return;
}
File file = LittleFS.open("/test_example.txt", "r");
if (!file)
{
Serial.println("Failed to open file for reading");
return;
}
Serial.println("File Content:");
while (file.available())
{
Serial.write(file.read());
}
file.close();
Serial.println("\n[*] Creating AP");
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid, password);
Serial.print("[+] AP Created with IP Gateway ");
Serial.println(WiFi.softAPIP());
// Define a route to serve the HTML page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{
Serial.println("ESP32 Web Server: New request received:"); // for debugging
Serial.println("GET /"); // for debugging
request->send(LittleFS, "/index.html", "text/html"); });
// Define a route to serve the CSS file
server.on("/style.css", HTTP_GET, [](AsyncWebServerRequest *request)
{
Serial.println("ESP32 Web Server: New request received:"); // for debugging
Serial.println("GET /style.css"); // for debugging
request->send(LittleFS, "/css/style.css", "text/css"); });
// Start the server
server.begin();
}
void loop() {}