-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLilAP.cpp
More file actions
54 lines (43 loc) · 1.47 KB
/
Copy pathLilAP.cpp
File metadata and controls
54 lines (43 loc) · 1.47 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
//LilAP.ino
//pop this in arduino ide as an ino
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <LittleFS.h>
// Network Credentials for Local AP Mode
const char* ap_ssid = "LocalDevKit_C3";
const char* ap_pass = "gamedev123"; // Min 8 chars for WPA2
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
delay(1000);
// Initialize LittleFS (or swap with SD.begin() if using an SD card module)
if (!LittleFS.begin(true)) {
Serial.println("An Error has occurred while mounting LittleFS");
return;
}
Serial.println("Filesystem mounted successfully.");
// Configure ESP32-C3 as an Access Point
WiFi.softAP(ap_ssid, ap_pass);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
// Route for root / index.html
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(LittleFS, "/index.html", "text/html");
});
// Serve all static assets (scripts, wasm blobs, editors) from root directory
server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html");
// Handle 404s
server.onNotFound([](AsyncWebServerRequest *request){
request->send(404, "text/plain", "Not found on ESP32-C3 Host.");
});
// Start server
server.begin();
Serial.println("Localhost web server active.");
}
void loop() {
// Asynchronous server runs in background callbacks; loop remains lean.
vTaskDelay(pdMS_TO_TICKS(1000));
}