diff --git a/Doorbell-Speaker.ino b/Doorbell-Speaker.ino index 6a0c0a5..54397ca 100644 --- a/Doorbell-Speaker.ino +++ b/Doorbell-Speaker.ino @@ -17,6 +17,7 @@ https://randomnerdtutorials.com/esp32-web-server-arduino-ide/ HardwareSerial mySoftwareSerial(1); DFRobotDFPlayerMini myDFPlayer; +int volume = 10; const char* ssid = "LeWe"; const char* password = "5275274365464843"; @@ -73,7 +74,7 @@ void setup() digitalWrite(ledPin, HIGH); myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms - myDFPlayer.volume(12); //Set volume value (0~30). + myDFPlayer.volume(volume); //Set volume value (0~30). myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); @@ -111,7 +112,19 @@ void loop() { // turns the GPIOs on and off if (header.indexOf("GET /bell/on") >= 0) { + + ledState = "on"; + digitalWrite(ledPin, HIGH); + timestamp = millis(); + myDFPlayer.setTimeOut(500); //Set serial communication time out 500ms + //myDFPlayer.volume(12); //Set volume value (0~30). + myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); + myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); + + myDFPlayer.play(1); //Play the first mp3 + + /* if (myDFPlayer.available()) { Serial.println("GPIO 26 on"); ledState = "on"; @@ -135,6 +148,16 @@ void loop() { digitalWrite(ledPin, LOW); delay(500); } + }*/ + } + else if (header.indexOf("GET /volume/") >= 0) { // yes, I know this is not RESTful + String str1 = header; + str1 = str1.substring(header.indexOf("GET /volume/") + 12); + volume = str1.substring(0, str1.indexOf(" ")).toInt(); + if (volume >= 0 && volume <= 30) { + myDFPlayer.volume(volume); + Serial.print("volume set to "); + Serial.println(volume); } } @@ -149,9 +172,10 @@ void loop() { client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"); client.println(".button2 {background-color: #555555;}"); - client.println("
LED - State " + ledState + "
"); - client.println(""); + client.println("Volume " + String(volume) + "
"); + client.println(""); client.println(""); // The HTTP response ends with another blank line