diff --git a/doorbell/Doorbell-Speaker.ino b/doorbell/Doorbell-Speaker.ino index 995a733..5866ac0 100644 --- a/doorbell/Doorbell-Speaker.ino +++ b/doorbell/Doorbell-Speaker.ino @@ -36,6 +36,8 @@ unsigned long previousMillis = 0; unsigned long interval = 120000; unsigned long lastcheck = 120000; +unsigned long lastring = 0; + void setup() { btStop(); // turn off bluetooth @@ -112,6 +114,22 @@ void loop() { client.println("}"); 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) { client.println("HTTP/1.1 200 OK"); client.println("Content-type: application/json; charset=utf-8"); @@ -177,10 +195,11 @@ void loop() { // turns the GPIOs on and off if (header.indexOf("GET /bell/on") >= 0) { 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; - str1 = str1.substring(header.indexOf("GET /volume/") + 12); + str1 = str1.substring(header.indexOf("GET /setvolume/") + 15); volume = str1.substring(0, str1.indexOf(" ")).toInt(); 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;}"); client.println("
Volume: " + String(volume) + "
"); + client.println("Volume: " + String(volume) + "
"); client.println(""); client.println("dfplayer status: " + printDetail(dfPlayer.readType(), dfPlayer.read()) + "
"); client.println("