diff --git a/examples/WebRadio/WebRadio.ino b/examples/WebRadio/WebRadio.ino index 54309b8..51bb012 100644 --- a/examples/WebRadio/WebRadio.ino +++ b/examples/WebRadio/WebRadio.ino @@ -58,7 +58,7 @@ Currently Playing: %s
function updateTitle() { var x = new XMLHttpRequest(); x.open("GET", "title"); - x.onload = function() { document.getElementById("titlespan").innerHTML=x.responseText; setTimeout(updateTitle, 1000); } + x.onload = function() { document.getElementById("titlespan").innerHTML=x.responseText; setTimeout(updateTitle, 5000); } x.send(); } setTimeout(updateTitle, 1000); @@ -73,7 +73,16 @@ Volume:
-Status: %s +Status: %s +
Current URL: %s
@@ -87,9 +96,10 @@ Change URL: void IndexHTML() { - char *webbuff = (char*)malloc(2048); - snprintf_P(webbuff, 2048, INDEX, title, volume, volume, status, url); - webbuff[2047] = 0; + int sz=1500; + char *webbuff = (char*)malloc(sz); + snprintf_P(webbuff, sz, INDEX, title, volume, volume, status, url); + webbuff[sz-1-1] = 0; server.send(200, "text/html", webbuff ); free(webbuff); } @@ -104,6 +114,11 @@ void GetTitle() server.send(200, "text/plain", title); } +void GetStatus() +{ + server.send(200, "text/plain", status); +} + void SetVol() { if (server.hasArg("vol")) { @@ -170,20 +185,19 @@ void MDCallback(void *cbData, const char *type, bool isUnicode, Stream *stream) if (strstr(type, "Title")) { strncpy(title, stream->readString().c_str(), sizeof(title)); title[sizeof(title)-1] = 0; - Serial.printf("Set title: %s\n", title); +// Serial.printf("Set title: %s\n", title); } else { - Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, type, stream->readString().c_str()); +// Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, type, stream->readString().c_str()); } - - Serial.flush(); +// Serial.flush(); } void StatusCallback(void *cbData, int code, const char *string) { const char *ptr = reinterpret_cast(cbData); - Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, string); +// Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, string); strncpy(status, string, sizeof(status)-1); status[sizeof(status)-1] = 0; - Serial.flush(); +// Serial.flush(); } void setup() @@ -217,6 +231,7 @@ void setup() server.on("/", HTTP_GET, IndexHTML); server.on("/setvol", HTTP_GET, SetVol); server.on("/title", HTTP_GET, GetTitle); + server.on("/status", HTTP_GET, GetStatus); server.on("/changeurl", HTTP_POST, ChangeURL); server.onNotFound(Send404); server.begin(); @@ -235,15 +250,17 @@ void loop() { static int lastms = 0; server.handleClient(); - if (!decoder) return; + if (millis()-lastms > 1000) { + lastms = millis(); + Serial.printf("Running for %d seconds...Free mem=%d\n", lastms/1000, ESP.getFreeHeap()); + //Serial.flush(); + } + + if (!decoder) return; + if (decoder->isRunning()) { strcpy(status, "OK"); // By default we're OK unless the decoder says otherwise - if (millis()-lastms > 1000) { - lastms = millis(); - Serial.printf("Running for %d seconds...\n", lastms/1000); - Serial.flush(); - } if (!decoder->loop()) { Serial.println("Stopping decoder"); decoder->stop();