garage_esp32: basic synchronous wifi
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/*
|
||||
* Doorbell Speaker for WEMOS D1 mini with dfplayer
|
||||
* by Tilman Liero
|
||||
* www.tilman.de
|
||||
*
|
||||
* Sources:
|
||||
* dfplayer library: https://github.com/DFRobot/DFRobotDFPlayerMini via https://wolles-elektronikkiste.de/dfplayer-mini-ansteuerung-mit-dem-arduino
|
||||
* info on how to use dfplayer with WEMOS D1: https://forum.arduino.cc/t/dfplayer-mini-mit-wemos-d1-uno/677980/3
|
||||
* WEMOS D1 WiFi setup: https://averagemaker.com/2018/04/how-to-set-up-wifi-on-a-wemos.html
|
||||
@@ -42,7 +45,8 @@ void setup()
|
||||
dfPlayer.EQ(DFPLAYER_EQ_NORMAL);
|
||||
dfPlayer.outputDevice(DFPLAYER_DEVICE_SD);
|
||||
|
||||
Serial.println("Connect WiFi");
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
WiFi.hostname("Doorbell");
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
@@ -59,7 +63,7 @@ void setup()
|
||||
server.begin();
|
||||
delay(500);
|
||||
dfPlayer.play(2); // Play the second mp3
|
||||
|
||||
|
||||
Serial.println("Setup completed");
|
||||
}
|
||||
|
||||
@@ -67,7 +71,7 @@ void setup()
|
||||
void loop() {
|
||||
|
||||
WiFiClient client = server.available(); // Listen for incoming clients
|
||||
|
||||
|
||||
if (client) {
|
||||
String currentLine = ""; // make a String to hold incoming data from the client
|
||||
while (client.connected()) { // loop while the client's connected
|
||||
@@ -106,7 +110,7 @@ void loop() {
|
||||
dfPlayer.play(fileNo);
|
||||
}
|
||||
}
|
||||
else if (header.indexOf("GET /setvolume/") >= 0) {
|
||||
else if (header.indexOf("GET /setvolume/") >= 0) {
|
||||
String str1 = header;
|
||||
str1 = str1.substring(header.indexOf("GET /setvolume/") + 15);
|
||||
volume = str1.substring(0, str1.indexOf(" ")).toInt();
|
||||
@@ -122,7 +126,15 @@ void loop() {
|
||||
Serial.print("Volume set to ");
|
||||
Serial.println(volume);
|
||||
}
|
||||
|
||||
else if (header.indexOf("GET /restart") >= 0) {
|
||||
Serial.println("Restarting...");
|
||||
ESP.restart();
|
||||
}
|
||||
else if (header.indexOf("GET /dfreset") >= 0) {
|
||||
Serial.println("Reset dfplayer...");
|
||||
dfPlayer.reset();
|
||||
}
|
||||
|
||||
// Display the HTML web page
|
||||
client.println("<!DOCTYPE html><html>");
|
||||
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
|
||||
|
||||
Reference in New Issue
Block a user