diff --git a/data/www/index.html b/data/www/index.html
index c606064..323ec7b 100644
--- a/data/www/index.html
+++ b/data/www/index.html
@@ -16,6 +16,10 @@
+
+ Lecture en cours.
+ Temps restant avant veille : 01:00:00.
+
diff --git a/data/www/script.js b/data/www/script.js
index 0bca97c..4036fc0 100644
--- a/data/www/script.js
+++ b/data/www/script.js
@@ -1,4 +1,4 @@
-const GLOBAL_TIMEOUT = 10000;
+const GLOBAL_TIMEOUT = 3500;
let connectionOk = true;
let statusTimeout = null;
let selectedFile = "";
@@ -66,6 +66,16 @@ function handleStatus(data) {
document.getElementById("volume-current").innerText = data.volume.current;
document.getElementById("volume-increase").disabled = !data.volume.canIncrease;
document.getElementById("volume-decrease").disabled = !data.volume.canDecrease;
+
+ document.getElementById("remainingTimeBeforeSleep").innerText = secondsToHumanDuration(data.remainingSecondsBeforeSleep);
+
+ const playingStatus = document.getElementById("playingStatus");
+ if (data.playing) {
+ playingStatus.classList.remove("w3-hide");
+ } else {
+ playingStatus.classList.add("w3-hide");
+ }
+
statusTimeout = setTimeout(loadStatus, GLOBAL_TIMEOUT);
}
@@ -112,6 +122,11 @@ function handleError(error) {
statusTimeout = setTimeout(loadStatus, GLOBAL_TIMEOUT);
}
+function secondsToHumanDuration(seconds) {
+ console.log({seconds});
+ return new Date(seconds * 1000).toISOString().slice(11, 19);
+}
+
(() => {
loadStatus().then(() => listFiles());
statusTimeout = setTimeout(loadStatus, GLOBAL_TIMEOUT);
diff --git a/src/webHandlers.cpp b/src/webHandlers.cpp
index 8a825ec..3c1a924 100644
--- a/src/webHandlers.cpp
+++ b/src/webHandlers.cpp
@@ -28,7 +28,7 @@ void onStatus(AsyncWebServerRequest *request)
Serial.println("Status");
AsyncResponseStream *response = request->beginResponseStream("application/json");
- StaticJsonDocument<96> root;
+ StaticJsonDocument<128> root;
String file = preferences.getString(SELECTED_FILE, "");
root["files"]["selected"] = file.c_str();
@@ -38,6 +38,15 @@ void onStatus(AsyncWebServerRequest *request)
volume["canDecrease"] = currentVolume > 0;
volume["canIncrease"] = currentVolume < 21;
+ if (!audio.isRunning())
+ {
+ root["remainingSecondsBeforeSleep"] = (DEEP_SLEEP_DELAY_MS - (millis() - lastActionTime)) / 1000;
+ }
+ else {
+ root["remainingSecondsBeforeSleep"] = DEEP_SLEEP_DELAY_MS / 1000;
+ }
+ root["playing"] = audio.isRunning();
+
serializeJson(root, *response);
request->send(response);
}