diff --git a/doorbell4-esp32/doorbell4-esp32.ino b/doorbell4-esp32/doorbell4-esp32.ino index 1bb0ae4..e825f6a 100644 --- a/doorbell4-esp32/doorbell4-esp32.ino +++ b/doorbell4-esp32/doorbell4-esp32.ino @@ -12,8 +12,8 @@ DFRobotDFPlayerMini dfPlayer; int volume = 22; -const char* ssid = "SSID"; -const char* password = "PASSWORD"; +const char* ssid = "Pixel 4a TL"; +const char* password = "20170618sn"; WiFiServer server(80); String header; @@ -37,7 +37,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); @@ -64,6 +65,13 @@ void loop() { WiFiClient client = server.available(); // Listen for incoming clients if (client) { + + // get player status + String playerStatus = "not available"; + if (dfPlayer.available()) { + playerStatus = getPlayerStatus(dfPlayer.readType(), dfPlayer.read()); + } + String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, @@ -117,6 +125,10 @@ void loop() { Serial.print("Volume set to "); Serial.println(volume); } + if (header.indexOf("GET /restart") >= 0) { + Serial.println("Restarting..."); + ESP.restart(); + } // Display the HTML web page client.println(""); @@ -130,6 +142,11 @@ void loop() { client.println("

Doorbell

"); client.println("

Volume: " + String(volume) + "

"); client.println("

"); + + client.println("

Status dfplayer: "); + client.println(playerStatus); + client.println("

"); + client.println(""); // The HTTP response ends with another blank line @@ -177,3 +194,38 @@ void loop() { Serial.println(""); } } + +String getPlayerStatus(uint8_t type, int value) { + switch (type) { + case TimeOut: + return "Time Out!"; + case WrongStack: + return "Stack Wrong!"; + case DFPlayerCardInserted: + return "Card Inserted!"; + case DFPlayerCardRemoved: + return "Card Removed!"; + case DFPlayerCardOnline: + return "Card Online!"; + case DFPlayerPlayFinished: + return "Play Finished!"; + case DFPlayerError: + switch (value) { + case Busy: + return "Error: Card not found"; + case Sleeping: + return "Error: Sleeping"; + case SerialWrongStack: + return "Error: Get Wrong Stack"; + case CheckSumNotMatch: + return "Error: Check Sum Not Match"; + case FileIndexOut: + return "Error: File Index Out of Bound"; + case FileMismatch: + return "Error: Cannot Find File"; + case Advertise: + return "Error: In Advertise"; + } + } + return "unknown"; +}