status message, better reconnect and sounds

This commit is contained in:
2021-09-14 17:21:52 +02:00
parent c669dfed5b
commit 53b4cd808c
+21 -7
View File
@@ -5,11 +5,13 @@ https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299
https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_DFPlayer_full/ESP32_DFPlayer_full.ino
https://github.com/pcbreflux/espressif/blob/master/esp32/arduino/sketchbook/ESP32_DFPlayer_full/setup.png
https://randomnerdtutorials.com/esp32-web-server-arduino-ide/
https://randomnerdtutorials.com/solved-reconnect-esp32-to-wifi/
*/
/* Anmerkungen:
- Übertragung aus Arduino IDE mit Board "ESP32 Dev Module", siehe https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md
- Zum Übertragen an das ESP-32-WROOM muss (manchmal?) der BOOT-Button gedrückt werden
- Die Library DFRobotDFPlayerMini-1.0.3.zip muss in der Arduino IDE über Sketch > Bibliothek einbinden > .ZIP-Bibliothek geöffnet werden
*/
#include <Arduino.h>
@@ -29,7 +31,9 @@ const int ledPin = 26;
int charCount = 0;
unsigned long previousMillis = 0;
unsigned long interval = 120000;
unsigned long lastcheck = 120000;
void setup()
{
@@ -76,14 +80,13 @@ void setupServer() {
server.begin();
delay(500);
dfPlayer.play(2); //Play the second mp3
dfPlayer.play(2); // play the second mp3
digitalWrite(ledPin, HIGH);
Serial.println("Setup completed");
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) {
WiFiClient client = server.available(); // Listen for incoming clients
@@ -107,10 +110,13 @@ void loop() {
client.println();
// turns the GPIOs on and off
if (header.indexOf("GET /bell/on") >= 0) {
if (header.indexOf("GET /") >= 0) {
client.println("{ \"status\": \"true\" }");
}
else if (header.indexOf("GET /bell/on") >= 0) {
dfPlayer.play(1); //Play the first mp3
}
else if (header.indexOf("GET /volume/") >= 0) { // yes, I know this is not RESTful
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();
@@ -162,9 +168,15 @@ void loop() {
Serial.println("");
}
}
else {
else if (lastcheck >= interval) {
Serial.println("Reconnecting...");
setupServer();
dfPlayer.play(3); // play the third mp3
WiFi.disconnect();
WiFi.reconnect();
previousMillis = millis();
}
else {
lastcheck = millis() - previousMillis;
}
}
@@ -212,10 +224,12 @@ String printDetail(uint8_t type, int value){
return "Error: In Advertise";
break;
default:
return "UNKNOWN ERROR";
break;
}
break;
default:
return "UNKNOWN TYPE";
break;
}
}