documentation

This commit is contained in:
2023-05-12 15:03:24 +02:00
parent 36909ebbce
commit ddf7fc5188
2 changed files with 19 additions and 54 deletions
+11 -52
View File
@@ -1,5 +1,5 @@
/**
* WiFi Doorbell for ESP32
* WiFi Doorbell for ESP32 with dfplayer
* by Tilman Liero
* www.tilman.de
**/
@@ -12,8 +12,8 @@
DFRobotDFPlayerMini dfPlayer;
int volume = 22;
const char* ssid = "Pixel 4a TL";
const char* password = "20170618sn";
const char* ssid = "SSID";
const char* password = "PASSWORD";
WiFiServer server(80);
String header;
@@ -27,6 +27,8 @@ void setup()
// start serial output
Serial.begin(115200);
Serial.println();
btStop(); // turn off bluetooth
Serial.println("Connect dfplayer");
Serial1.begin(9600, SERIAL_8N1, 18, 19); // speed, type, TX, RX
@@ -63,15 +65,8 @@ void setup()
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
if (client) {
// get player status
String playerStatus = "<i>not available</i>";
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,
@@ -125,10 +120,14 @@ void loop() {
Serial.print("Volume set to ");
Serial.println(volume);
}
if (header.indexOf("GET /restart") >= 0) {
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>");
@@ -142,11 +141,6 @@ void loop() {
client.println("<body><h1>Doorbell</h1>");
client.println("<p>Volume: <a href=\"/setvolume/" + String(volume-1) + "\"><button class=\"button2\">&minus;</button></a> " + String(volume) + " <a href=\"/setvolume/" + String(volume+1) + "\"><button class=\"button2\">&plus;</button></a></p>");
client.println("<p><a href=\"/bell/on\"><button class=\"button\">Ring</button></a></p>");
client.println("<p style='font-size:80%'>Status dfplayer: ");
client.println(playerStatus);
client.println("</p>");
client.println("</body></html>");
// The HTTP response ends with another blank line
@@ -194,38 +188,3 @@ 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";
}