From d06dcf11231c811e4c6f39d130d2eed637b30c0f Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sun, 24 Dec 2017 09:31:36 -0800 Subject: [PATCH] Include type and volume in checksum, cleanup code --- examples/WebRadio/WebRadio.ino | 57 +++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/examples/WebRadio/WebRadio.ino b/examples/WebRadio/WebRadio.ino index 936dff9..77543a8 100644 --- a/examples/WebRadio/WebRadio.ino +++ b/examples/WebRadio/WebRadio.ino @@ -49,10 +49,12 @@ char url[96]; char status[64]; bool newUrl = false; bool isAAC = false; +int retryms = 0; typedef struct { char url[96]; bool isAAC; + int16_t volume; int16_t checksum; } Settings; @@ -238,15 +240,12 @@ void setup() delay(1000); Serial.printf_P(PSTR("Connecting to WiFi\n")); -// WiFi.disconnect(); -// WiFi.softAPdisconnect(true); + WiFi.disconnect(); + WiFi.softAPdisconnect(true); WiFi.mode(WIFI_STA); -// WiFi.hostname("melody"); + WiFi.hostname("melody"); -// byte zero[] = {0,0,0,0}; -// WiFi.config(zero, zero, zero, zero); - WiFi.begin(SSID, PASSWORD); // Try forever @@ -276,12 +275,13 @@ void setup() void StartNewURL() { - Serial.printf_P(PSTR("Changing URL to: ")); - Serial.println(url); + Serial.printf_P(PSTR("Changing URL to: %s, vol=%d\n"), url, volume); + newUrl = false; // Stop and free existing ones + Serial.printf_P(PSTR("Before stop...Free mem=%d\n"), ESP.getFreeHeap()); StopPlaying(); - + Serial.printf_P(PSTR("After stop...Free mem=%d\n"), ESP.getFreeHeap()); SaveSettings(); file = new AudioFileSourceICYStream(url); @@ -297,6 +297,7 @@ void StartNewURL() Serial.printf_P(PSTR("Can't connect to URL")); StopPlaying(); strcpy_P(status, PSTR("Unable to connect to URL")); + retryms = millis() + 2000; } } @@ -312,10 +313,13 @@ void LoadSettings() EEPROM.end(); int16_t sum = 0x1234; for (size_t i=0; i(&s); EEPROM.begin(sizeof(s)); for (size_t i=0; iisRunning()) { + strcpy_P(status, PSTR("Playing")); // By default we're OK unless the decoder says otherwise + if (!decoder->loop()) { + Serial.printf_P(PSTR("Stopping decoder\n")); + StopPlaying(); + retryms = millis() + 2000; + } +} + +} + void loop() { static int lastms = 0; - static int retryms = 0; if (millis()-lastms > 1000) { lastms = millis(); Serial.printf_P(PSTR("Running for %d seconds...Free mem=%d\n"), lastms/1000, ESP.getFreeHeap()); @@ -356,22 +375,15 @@ void loop() StartNewURL(); } - if (decoder && decoder->isRunning()) { - strcpy_P(status, PSTR("Playing")); // By default we're OK unless the decoder says otherwise - if (!decoder->loop()) { - Serial.printf_P(PSTR("Stopping decoder\n")); - StopPlaying(); - retryms = millis() + 2000; - } - } else { - // Nothing here - } - + PumpDecoder(); + char *reqUrl; char *params; WiFiClient client = server.available(); + PumpDecoder(); char *reqBuff = (char *)alloca(384); if (client && WebReadRequest(&client, reqBuff, 384, &reqUrl, ¶ms)) { + PumpDecoder(); if (IsIndexHTML(reqUrl)) { HandleIndex(&client); } else if (!strcmp_P(reqUrl, PSTR("stop"))) { @@ -388,6 +400,7 @@ void loop() WebError(&client, 404, NULL, false); } } + PumpDecoder(); if (client) { client.flush(); client.stop();