mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-11-21 23:48:07 +01:00
Use serve static for files
This commit is contained in:
parent
d0f64ad153
commit
bebf8b5af3
5 changed files with 22 additions and 28 deletions
|
@ -22,10 +22,6 @@
|
||||||
<h3 class="w3-padding">Fichier sélectionné</h3>
|
<h3 class="w3-padding">Fichier sélectionné</h3>
|
||||||
<p class="w3-xxlarge" id="selected-file">Aucun</p>
|
<p class="w3-xxlarge" id="selected-file">Aucun</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="w3-padding w3-center">
|
|
||||||
<a href="https://gabnotes.org">Gabriel Augendre 2022</a>
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -15,5 +15,5 @@ framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
ESP Async WebServer
|
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
||||||
AsyncTCP
|
AsyncTCP
|
||||||
|
|
44
src/main.cpp
44
src/main.cpp
|
@ -6,21 +6,30 @@ const char *ssid = "buzzer";
|
||||||
const char *password = "123456789";
|
const char *password = "123456789";
|
||||||
|
|
||||||
const byte led = 2;
|
const byte led = 2;
|
||||||
|
bool ledOn = false;
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
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()
|
void setup()
|
||||||
{
|
{
|
||||||
// Setup serial
|
// Setup serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
/*
|
|
||||||
Wait for serial monitor to be connected.
|
|
||||||
Remove this when running without computer.
|
|
||||||
*/
|
|
||||||
while (!Serial)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
Serial.println("\n");
|
|
||||||
pinMode(led, OUTPUT);
|
pinMode(led, OUTPUT);
|
||||||
digitalWrite(led, LOW);
|
digitalWrite(led, LOW);
|
||||||
|
|
||||||
|
@ -37,7 +46,7 @@ void setup()
|
||||||
while (file)
|
while (file)
|
||||||
{
|
{
|
||||||
Serial.print("File: ");
|
Serial.print("File: ");
|
||||||
Serial.println(file.name());
|
Serial.println(file.path());
|
||||||
file.close();
|
file.close();
|
||||||
file = root.openNextFile();
|
file = root.openNextFile();
|
||||||
}
|
}
|
||||||
|
@ -49,23 +58,12 @@ void setup()
|
||||||
Serial.println(WiFi.softAPIP());
|
Serial.println(WiFi.softAPIP());
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
server.on("/play", HTTP_GET, onPlay);
|
||||||
{ request->send(SPIFFS, "/index.html", "text/html"); });
|
server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.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.begin();
|
server.begin();
|
||||||
Serial.println("Server ready!");
|
Serial.println("Server ready!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// put your main code here, to run repeatedly:
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue