diff --git a/data/index.html b/data/www/index.html similarity index 87% rename from data/index.html rename to data/www/index.html index bd87476..6f8bf0f 100644 --- a/data/index.html +++ b/data/www/index.html @@ -22,10 +22,6 @@

Fichier sélectionné

Aucun

- -
- Gabriel Augendre 2022 -
\ No newline at end of file diff --git a/data/script.js b/data/www/script.js similarity index 100% rename from data/script.js rename to data/www/script.js diff --git a/data/w3.css b/data/www/w3.css similarity index 100% rename from data/w3.css rename to data/www/w3.css diff --git a/platformio.ini b/platformio.ini index a038c8a..fee0b73 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,5 +15,5 @@ framework = arduino monitor_speed = 115200 lib_deps = - ESP Async WebServer + https://github.com/me-no-dev/ESPAsyncWebServer.git AsyncTCP diff --git a/src/main.cpp b/src/main.cpp index 5053446..d8cffd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,21 +6,30 @@ const char *ssid = "buzzer"; const char *password = "123456789"; const byte led = 2; +bool ledOn = false; AsyncWebServer server(80); +void onPlay(AsyncWebServerRequest *request) +{ + Serial.println("Toggling LED"); + if (ledOn) + { + ledOn = false; + digitalWrite(led, LOW); + } + else + { + ledOn = true; + digitalWrite(led, HIGH); + } + request->send(200); +} + void setup() { // Setup serial Serial.begin(115200); - /* - Wait for serial monitor to be connected. - Remove this when running without computer. - */ - while (!Serial) - { - } - Serial.println("\n"); pinMode(led, OUTPUT); digitalWrite(led, LOW); @@ -37,7 +46,7 @@ void setup() while (file) { Serial.print("File: "); - Serial.println(file.name()); + Serial.println(file.path()); file.close(); file = root.openNextFile(); } @@ -49,23 +58,12 @@ void setup() Serial.println(WiFi.softAPIP()); // Server - server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) - { request->send(SPIFFS, "/index.html", "text/html"); }); - server.on("/w3.css", HTTP_GET, [](AsyncWebServerRequest *request) - { request->send(SPIFFS, "/w3.css", "text/css"); }); - server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request) - { request->send(SPIFFS, "/script.js", "text/javascript"); }); - server.on("/play", HTTP_GET, [](AsyncWebServerRequest *request) - { - // TODO: play file through speaker - Serial.println("/play"); - request->send(200); }); - + server.on("/play", HTTP_GET, onPlay); + server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html"); server.begin(); Serial.println("Server ready!"); } void loop() { - // put your main code here, to run repeatedly: -} \ No newline at end of file +}