mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-12-26 16:01:49 +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>
|
||||
<p class="w3-xxlarge" id="selected-file">Aucun</p>
|
||||
</div>
|
||||
|
||||
<div class="w3-padding w3-center">
|
||||
<a href="https://gabnotes.org">Gabriel Augendre 2022</a>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -15,5 +15,5 @@ framework = arduino
|
|||
monitor_speed = 115200
|
||||
|
||||
lib_deps =
|
||||
ESP Async WebServer
|
||||
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
||||
AsyncTCP
|
||||
|
|
44
src/main.cpp
44
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:
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue