Doorbell /last + bugfix
This commit is contained in:
@@ -36,6 +36,8 @@ unsigned long previousMillis = 0;
|
|||||||
unsigned long interval = 120000;
|
unsigned long interval = 120000;
|
||||||
unsigned long lastcheck = 120000;
|
unsigned long lastcheck = 120000;
|
||||||
|
|
||||||
|
unsigned long lastring = 0;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
btStop(); // turn off bluetooth
|
btStop(); // turn off bluetooth
|
||||||
@@ -112,6 +114,22 @@ void loop() {
|
|||||||
client.println("}");
|
client.println("}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if (header.indexOf("GET /last") >= 0) {
|
||||||
|
client.println("HTTP/1.1 200 OK");
|
||||||
|
client.println("Content-type: application/json; charset=utf-8");
|
||||||
|
client.println("Connection: close");
|
||||||
|
client.println();
|
||||||
|
client.println("{");
|
||||||
|
client.print(" \"value\": ");
|
||||||
|
if (lastring <= 0) {
|
||||||
|
client.println(-1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
client.println(millis() - lastring);
|
||||||
|
}
|
||||||
|
client.println("}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
else if (header.indexOf("GET /volume") >= 0) {
|
else if (header.indexOf("GET /volume") >= 0) {
|
||||||
client.println("HTTP/1.1 200 OK");
|
client.println("HTTP/1.1 200 OK");
|
||||||
client.println("Content-type: application/json; charset=utf-8");
|
client.println("Content-type: application/json; charset=utf-8");
|
||||||
@@ -177,10 +195,11 @@ void loop() {
|
|||||||
// turns the GPIOs on and off
|
// turns the GPIOs on and off
|
||||||
if (header.indexOf("GET /bell/on") >= 0) {
|
if (header.indexOf("GET /bell/on") >= 0) {
|
||||||
dfPlayer.play(1); // play the first mp3
|
dfPlayer.play(1); // play the first mp3
|
||||||
|
lastring = millis();
|
||||||
}
|
}
|
||||||
else if (header.indexOf("GET /volume/") >= 0) { // yes, I know this is not RESTful
|
else if (header.indexOf("GET /setvolume/") >= 0) { // yes, I know this is not RESTful
|
||||||
String str1 = header;
|
String str1 = header;
|
||||||
str1 = str1.substring(header.indexOf("GET /volume/") + 12);
|
str1 = str1.substring(header.indexOf("GET /setvolume/") + 15);
|
||||||
volume = str1.substring(0, str1.indexOf(" ")).toInt();
|
volume = str1.substring(0, str1.indexOf(" ")).toInt();
|
||||||
|
|
||||||
if (volume < 0) {
|
if (volume < 0) {
|
||||||
@@ -204,7 +223,7 @@ void loop() {
|
|||||||
client.println(".button2 { background-color: #4CAF50; border: none; color: white; padding: 4px 10px; text-decoration: none; margin: 1px; cursor: pointer;}</style></head>");
|
client.println(".button2 { background-color: #4CAF50; border: none; color: white; padding: 4px 10px; text-decoration: none; margin: 1px; cursor: pointer;}</style></head>");
|
||||||
|
|
||||||
client.println("<body><h1>LeWe Türklingel</h1>");
|
client.println("<body><h1>LeWe Türklingel</h1>");
|
||||||
client.println("<p>Volume: <a href=\"/volume/" + String(volume-1) + "\"><button class=\"button2\">−</button></a> " + String(volume) + " <a href=\"/volume/" + 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\">Klingeln</button></a></p>");
|
client.println("<p><a href=\"/bell/on\"><button class=\"button\">Klingeln</button></a></p>");
|
||||||
client.println("<p style='margin-top: 40px; font-size: 8px;'>dfplayer status: " + printDetail(dfPlayer.readType(), dfPlayer.read()) + "</p>");
|
client.println("<p style='margin-top: 40px; font-size: 8px;'>dfplayer status: " + printDetail(dfPlayer.readType(), dfPlayer.read()) + "</p>");
|
||||||
client.println("</body></html>");
|
client.println("</body></html>");
|
||||||
|
|||||||
Reference in New Issue
Block a user