Doorbell esp32
This commit is contained in:
@@ -12,8 +12,8 @@
|
|||||||
DFRobotDFPlayerMini dfPlayer;
|
DFRobotDFPlayerMini dfPlayer;
|
||||||
int volume = 22;
|
int volume = 22;
|
||||||
|
|
||||||
const char* ssid = "SSID";
|
const char* ssid = "Pixel 4a TL";
|
||||||
const char* password = "PASSWORD";
|
const char* password = "20170618sn";
|
||||||
|
|
||||||
WiFiServer server(80);
|
WiFiServer server(80);
|
||||||
String header;
|
String header;
|
||||||
@@ -37,7 +37,8 @@ void setup()
|
|||||||
dfPlayer.EQ(DFPLAYER_EQ_NORMAL);
|
dfPlayer.EQ(DFPLAYER_EQ_NORMAL);
|
||||||
dfPlayer.outputDevice(DFPLAYER_DEVICE_SD);
|
dfPlayer.outputDevice(DFPLAYER_DEVICE_SD);
|
||||||
|
|
||||||
Serial.println("Connect WiFi");
|
Serial.print("Connecting to ");
|
||||||
|
Serial.println(ssid);
|
||||||
WiFi.hostname("Doorbell");
|
WiFi.hostname("Doorbell");
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
@@ -64,6 +65,13 @@ void loop() {
|
|||||||
WiFiClient client = server.available(); // Listen for incoming clients
|
WiFiClient client = server.available(); // Listen for incoming clients
|
||||||
|
|
||||||
if (client) {
|
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
|
String currentLine = ""; // make a String to hold incoming data from the client
|
||||||
while (client.connected()) { // loop while the client's connected
|
while (client.connected()) { // loop while the client's connected
|
||||||
if (client.available()) { // if there's bytes to read from the client,
|
if (client.available()) { // if there's bytes to read from the client,
|
||||||
@@ -117,6 +125,10 @@ void loop() {
|
|||||||
Serial.print("Volume set to ");
|
Serial.print("Volume set to ");
|
||||||
Serial.println(volume);
|
Serial.println(volume);
|
||||||
}
|
}
|
||||||
|
if (header.indexOf("GET /restart") >= 0) {
|
||||||
|
Serial.println("Restarting...");
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
// Display the HTML web page
|
// Display the HTML web page
|
||||||
client.println("<!DOCTYPE html><html>");
|
client.println("<!DOCTYPE html><html>");
|
||||||
@@ -130,6 +142,11 @@ void loop() {
|
|||||||
client.println("<body><h1>Doorbell</h1>");
|
client.println("<body><h1>Doorbell</h1>");
|
||||||
client.println("<p>Volume: <a href=\"/setvolume/" + String(volume-1) + "\"><button class=\"button2\">−</button></a> " + String(volume) + " <a href=\"/setvolume/" + String(volume+1) + "\"><button class=\"button2\">+</button></a></p>");
|
client.println("<p>Volume: <a href=\"/setvolume/" + String(volume-1) + "\"><button class=\"button2\">−</button></a> " + String(volume) + " <a href=\"/setvolume/" + String(volume+1) + "\"><button class=\"button2\">+</button></a></p>");
|
||||||
client.println("<p><a href=\"/bell/on\"><button class=\"button\">Ring</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>");
|
client.println("</body></html>");
|
||||||
|
|
||||||
// The HTTP response ends with another blank line
|
// The HTTP response ends with another blank line
|
||||||
@@ -177,3 +194,38 @@ void loop() {
|
|||||||
Serial.println("");
|
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";
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user