Skip to content

Commit 8fa32f1

Browse files
committed
v0.7.355
1 parent 442d970 commit 8fa32f1

File tree

19 files changed

+3311
-2574
lines changed

19 files changed

+3311
-2574
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ Work is in progress...
317317

318318
---
319319
## Version history
320+
#### v0.7.355
321+
- updating libraries ESP32-audioI2S and ESP32-vs1053_ext to the latest version
322+
- optimization of the web interface during playback
323+
- fixed one js bug. a [full update](#update-over-web-interface) with Sketch data upload is desirable
324+
- plugin example for esp deep sleep when playback is stopped (exsamples/plugins/deepsleep.ino)
325+
320326
#### v0.7.330
321327
**!!! a [full update](#update-over-web-interface) with Sketch data upload is required. After updating please press CTRL+F5 in browser !!!** \
322328
**Please backup playlist.csv and wifi.csv before updating.**

exsamples/plugins/deepsleep.ino

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**************************************************************
2+
3+
Example of esp32 deep sleep when playback is stopped.
4+
This file must be in the root directory of the sketch.
5+
6+
**************************************************************/
7+
#define SLEEP_DELAY 60 // 1 min
8+
#define WAKEUP_PIN_1 GPIO_NUM_12
9+
#define WAKEUP_LEVEL LOW
10+
11+
Ticker deepSleepTicker;
12+
13+
void goToSleep(){
14+
if(BRIGHTNESS_PIN!=255) analogWrite(BRIGHTNESS_PIN, 0); /* BRIGHTNESS_PIN added in v0.7.330 */
15+
esp_deep_sleep_start();
16+
}
17+
18+
void yoradio_on_setup(){
19+
esp_sleep_enable_ext0_wakeup(WAKEUP_PIN_1, WAKEUP_LEVEL);
20+
deepSleepTicker.attach(SLEEP_DELAY, goToSleep);
21+
}
22+
23+
void player_on_start_play(){
24+
deepSleepTicker.detach();
25+
}
26+
27+
void player_on_stop_play(){
28+
deepSleepTicker.attach(SLEEP_DELAY, goToSleep);
29+
}

yoRadio/audiohandlers.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ void audio_info(const char *info) {
1515
player.mode = STOPPED;
1616
player.stopInfo();
1717
}
18+
if (strstr(info, "not supported") != NULL){
19+
config.setTitle(info);
20+
netserver.requestOnChange(TITLE, 0);
21+
player.setOutputPins(false);
22+
player.setDefaults();
23+
if (player_on_stop_play) player_on_stop_play();
24+
player.mode = STOPPED;
25+
player.stopInfo();
26+
}
1827
}
1928

2029
void audio_bitrate(const char *info)

yoRadio/config.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
#include "player.h"
66
Config config;
77

8+
void DBGVB(const char *format, ...) {
9+
#ifdef DEBUG_V
10+
char buf[200];
11+
va_list args;
12+
va_start (args, format );
13+
vsnprintf(buf, 200, format, args);
14+
Serial.print("[DEBUG] ");
15+
Serial.print(buf);
16+
Serial.println();
17+
#endif
18+
}
19+
820
void Config::init() {
921
EEPROM.begin(EEPROM_SIZE);
1022
#if IR_PIN!=255

yoRadio/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#define TMP_PATH "/data/tmpfile.txt"
1414
#define INDEX_PATH "/data/index.dat"
1515

16+
void DBGVB(const char *format, ...);
17+
1618
struct config_t
1719
{
1820
unsigned int config_set; //must be 4262

yoRadio/data/www/script.js.gz

6 Bytes
Binary file not shown.

yoRadio/display_vu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum : uint16_t { VU_X = 4, VU_Y = 116, VU_BW = 24, VU_BH = 80, VU_BS = 4,
3838
enum : uint16_t { VU_X = 4, VU_Y = 90, VU_BW = 120, VU_BH = 20, VU_BS = 0, VU_NB = 12, VU_FS = 3, VU_HOR = 1, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY };
3939

4040
#elif DSP_MODEL==DSP_ILI9225 /* ILI9225 220x176 */
41-
enum : uint16_t { VU_X = 4, VU_Y = 80, VU_BW = 13, VU_BH = 56, VU_BS = 2, VU_NB = 8, VU_FS = 3, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY };
41+
enum : uint16_t { VU_X = 4, VU_Y = 80, VU_BW = 13, VU_BH = 56, VU_BS = 2, VU_NB = 8, VU_FS = 4, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY };
4242

4343
#elif (DSP_MODEL==DSP_ST7735 && DTYPE==INITR_MINI160x80) || (DSP_MODEL==DSP_GC9106) /* ST7735 160x80, GC9106 160x80 */
4444
enum : uint16_t { VU_X = 1, VU_Y = 30, VU_BW = 12, VU_BH = 36, VU_BS = 4, VU_NB = 8, VU_FS = 2, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY };

yoRadio/netserver.cpp

Lines changed: 95 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define MIN_MALLOC 24112
1616
#endif
1717

18-
#define CORS_DEBUG
18+
//#define CORS_DEBUG
1919

2020
NetServer netserver;
2121

@@ -40,21 +40,20 @@ void NetServer::takeMallocDog(){
4040
int mcb = heap_caps_get_free_size(MALLOC_CAP_8BIT);
4141
int mci = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
4242
(void)mci;
43-
log_i("[yoradio] webserver.on / - MALLOC_CAP_INTERNAL=%d, MALLOC_CAP_8BIT=%d", mci, mcb);
43+
DBGVB("MALLOC_CAP_8BIT=%d, MALLOC_CAP_INTERNAL=%d", mcb, mci);
4444
resumePlay = mcb < MIN_MALLOC;
4545
if (resumePlay) {
4646
player.toggle();
47-
while (player.isRunning()) {
48-
vTaskDelay(10);
49-
}
50-
vTaskDelay(50);
47+
vTaskDelay(150);
48+
xSemaphoreTake(player.playmutex, portMAX_DELAY);
5149
}
5250
}
5351

5452
void NetServer::giveMallocDog(){
5553
if (resumePlay) {
5654
resumePlay = false;
57-
vTaskDelay(100);
55+
vTaskDelay(150);
56+
xSemaphoreGive(player.playmutex);
5857
player.toggle();
5958
}
6059
}
@@ -63,13 +62,13 @@ bool NetServer::begin() {
6362
importRequest = false;
6463
irRecordEnable = false;
6564
webserver.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
66-
netserver.takeMallocDog();
6765
if (network.status == CONNECTED) {
68-
request->send(SPIFFS, "/www/index.html", String(), false, processor);
66+
netserver.htmlPath = PINDEX;
67+
netserver.chunkedHtmlPage(String(), request);
6968
}else{
70-
request->send(SPIFFS, "/www/settings.html", String(), false, processor);
69+
netserver.htmlPath = PSETTINGS;
70+
netserver.chunkedHtmlPage(String(), request);
7171
}
72-
netserver.giveMallocDog();
7372
});
7473

7574
webserver.serveStatic("/", SPIFFS, "/www/").setCacheControl("max-age=31536000");
@@ -81,34 +80,35 @@ bool NetServer::begin() {
8180
netserver.takeMallocDog();
8281
request->send(SPIFFS, PLAYLIST_PATH, "application/octet-stream");
8382
netserver.giveMallocDog();
83+
DBGVB("PLAYLIST_PATH client ip=%s", request->client()->remoteIP().toString().c_str());
84+
/*netserver.htmlPath = PPLAYLIST; // TODO
85+
netserver.chunkedHtmlPage("application/octet-stream", request);
86+
netserver.giveMallocDog();*/
8487
});
8588
webserver.on(INDEX_PATH, HTTP_GET, [](AsyncWebServerRequest * request) {
8689
request->send(SPIFFS, INDEX_PATH, "application/octet-stream");
8790
});
8891
webserver.on(SSIDS_PATH, HTTP_GET, [](AsyncWebServerRequest * request) {
89-
netserver.takeMallocDog();
90-
request->send(SPIFFS, SSIDS_PATH, "application/octet-stream");
91-
netserver.giveMallocDog();
92+
netserver.htmlPath = PSSIDS;
93+
netserver.chunkedHtmlPage("application/octet-stream", request);
9294
});
9395
webserver.on("/upload", HTTP_POST, [](AsyncWebServerRequest * request) {
9496
//request->send(200);
9597

9698
}, handleUpload);
9799
webserver.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){
98-
netserver.takeMallocDog();
99-
request->send(SPIFFS, "/www/update.html", String(), false, processor);
100-
netserver.giveMallocDog();
100+
netserver.htmlPath = PUPDATE;
101+
netserver.chunkedHtmlPage(String(), request);
101102
});
102103
webserver.on("/settings", HTTP_GET, [](AsyncWebServerRequest *request){
103-
netserver.takeMallocDog();
104-
request->send(SPIFFS, "/www/settings.html", String(), false, processor);
105-
netserver.giveMallocDog();
104+
netserver.htmlPath = PSETTINGS;
105+
netserver.chunkedHtmlPage(String(), request);
106106
});
107+
107108
#if IR_PIN!=255
108109
webserver.on("/ir", HTTP_GET, [](AsyncWebServerRequest *request){
109-
netserver.takeMallocDog();
110-
request->send(SPIFFS, "/www/ir.html", String(), false, processor);
111-
netserver.giveMallocDog();
110+
netserver.htmlPath = PIR;
111+
netserver.chunkedHtmlPage(String(), request);
112112
});
113113
#endif
114114
webserver.on("/update", HTTP_POST, [](AsyncWebServerRequest *request){
@@ -160,6 +160,66 @@ bool NetServer::begin() {
160160
return true;
161161
}
162162

163+
void NetServer::chunkedHtmlPage(const String& contentType, AsyncWebServerRequest *request){
164+
max = heap_caps_get_free_size(MALLOC_CAP_8BIT) / 32;
165+
htmlpos = 0;
166+
theend = false;
167+
DBGVB("chunkedHtmlPage client ip=%s", request->client()->remoteIP().toString().c_str());
168+
AsyncWebServerResponse *response = request->beginChunkedResponse(contentType, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
169+
if(netserver.theend) return 0;
170+
File htmlpage;
171+
switch(netserver.htmlPath){
172+
case PINDEX: {
173+
htmlpage = SPIFFS.open("/www/index.html", "r");
174+
break;
175+
}
176+
case PSETTINGS: {
177+
htmlpage = SPIFFS.open("/www/settings.html", "r");
178+
break;
179+
}
180+
case PUPDATE: {
181+
htmlpage = SPIFFS.open("/www/update.html", "r");
182+
break;
183+
}
184+
case PIR: {
185+
htmlpage = SPIFFS.open("/www/ir.html", "r");
186+
break;
187+
}
188+
case PPLAYLIST: {
189+
htmlpage = SPIFFS.open(PLAYLIST_PATH, "r");
190+
DBGVB("SPIFFS.open(PLAYLIST_PATH)");
191+
break;
192+
}
193+
case PSSIDS: {
194+
htmlpage = SPIFFS.open(SSIDS_PATH, "r");
195+
break;
196+
}
197+
default: {
198+
return 0;
199+
break;
200+
}
201+
}
202+
if(!htmlpage) return 0;
203+
uint32_t htmlpagesize = htmlpage.size();
204+
uint32_t len = htmlpagesize - netserver.htmlpos;
205+
if (len > maxLen) len = maxLen;
206+
if (len > netserver.max) len = netserver.max;
207+
if (len + netserver.htmlpos > htmlpagesize) {
208+
netserver.theend = true;
209+
len = htmlpagesize - netserver.htmlpos;
210+
}
211+
if (len > 0) {
212+
DBGVB("seek to %d in %s and read %d bytes", netserver.htmlpos, htmlpage.name(), len);
213+
htmlpage.seek(netserver.htmlpos, SeekSet);
214+
htmlpage.read(buffer, len);
215+
netserver.htmlpos = netserver.htmlpos + len;
216+
}
217+
if(htmlpage) htmlpage.close();
218+
return len;
219+
}, processor); // AsyncWebServerResponse
220+
request->send(response);
221+
}
222+
163223
void NetServer::loop() {
164224
if(shouldReboot){
165225
Serial.println("Rebooting...");
@@ -173,7 +233,7 @@ void NetServer::loop() {
173233
}
174234
if (importRequest) {
175235
if (importPlaylist()) {
176-
//requestOnChange(PLAYLIST, 0);
236+
requestOnChange(PLAYLIST, 0);
177237
}
178238
importRequest = false;
179239
}
@@ -400,7 +460,7 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
400460
display.putRequest({NEWMODE, PLAYER});
401461
return;
402462
}
403-
463+
/* RESETS */
404464
if (strcmp(cmd, "reset") == 0) {
405465
if (strcmp(val, "system") == 0) {
406466
config.store.smartstart=2;
@@ -465,7 +525,7 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
465525
requestOnChange(GETCONTROLS,clientId);
466526
return;
467527
}
468-
}
528+
} /* RESETS */
469529
if (strcmp(cmd, "volume") == 0) {
470530
byte v = atoi(val);
471531
player.setVol(v, false);
@@ -541,6 +601,9 @@ void NetServer::onWsMessage(void *arg, uint8_t *data, size_t len, uint8_t client
541601
player.toggle();
542602
resumePlay=false;
543603
}
604+
#ifdef MQTT_HOST
605+
mqttPublishPlaylist();
606+
#endif
544607
return;
545608
}
546609
#if IR_PIN!=255
@@ -589,6 +652,7 @@ bool NetServer::savePlaylist(const char* post) {
589652
} else {
590653
file.print(post);
591654
file.close();
655+
vTaskDelay(150);
592656
netserver.requestOnChange(PLAYLISTSAVED, 0);
593657
return true;
594658
}
@@ -650,9 +714,9 @@ void NetServer::requestOnChange(requestType_e request, uint8_t clientId) {
650714
config.indexPlaylist();
651715
config.initPlaylist();
652716
getPlaylist(clientId);
653-
#ifdef MQTT_HOST
717+
/*#ifdef MQTT_HOST
654718
mqttPublishPlaylist();
655-
#endif
719+
#endif*/
656720
break;
657721
}
658722
case GETACTIVE: {
@@ -808,6 +872,7 @@ String processor(const String& var) { // %Templates%
808872

809873
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
810874
if (!index) {
875+
netserver.takeMallocDog();
811876
request->_tempFile = SPIFFS.open(TMP_PATH , "w");
812877
}
813878
if (len) {
@@ -824,7 +889,7 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
824889
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
825890
switch (type) {
826891
case WS_EVT_CONNECT:
827-
if(config.store.audioinfo) Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
892+
if(config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
828893
/*netserver.requestOnChange(STATION, client->id());
829894
netserver.requestOnChange(TITLE, client->id());
830895
netserver.requestOnChange(VOLUME, client->id());
@@ -836,7 +901,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
836901

837902
break;
838903
case WS_EVT_DISCONNECT:
839-
if(config.store.audioinfo) Serial.printf("WebSocket client #%u disconnected\n", client->id());
904+
if(config.store.audioinfo) Serial.printf("[WEBSOCKET] client #%u disconnected\n", client->id());
840905
break;
841906
case WS_EVT_DATA:
842907
netserver.onWsMessage(arg, data, len, client->id());

yoRadio/netserver.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
#include "ESPAsyncWebServer.h"
66
#include "AsyncUDP.h"
77

8-
enum requestType_e { PLAYLIST, STATION, ITEM, TITLE, VOLUME, NRSSI, BITRATE, MODE, EQUALIZER, BALANCE, PLAYLISTSAVED, GETMODE, GETINDEX, GETACTIVE, GETSYSTEM, GETSCREEN, GETTIMEZONE, GETWEATHER, GETCONTROLS };
8+
enum requestType_e : uint8_t { PLAYLIST=1, STATION=2, ITEM=3, TITLE=4, VOLUME=5, NRSSI=6, BITRATE=7, MODE=8, EQUALIZER=9, BALANCE=10, PLAYLISTSAVED=11, GETMODE=12, GETINDEX=13, GETACTIVE=14, GETSYSTEM=15, GETSCREEN=16, GETTIMEZONE=17, GETWEATHER=18, GETCONTROLS=19 };
9+
enum htmlPath_e : uint8_t { PINDEX=1, PSETTINGS=2, PUPDATE=3, PIR=4, PPLAYLIST=5, PSSIDS=6 };
910

1011
class NetServer {
1112
public:
1213
uint8_t playlistrequest; // ClientId want the playlist
1314
bool importRequest;
1415
bool resumePlay;
16+
htmlPath_e htmlPath;
1517
public:
1618
NetServer() {};
1719
bool begin();
@@ -22,10 +24,13 @@ class NetServer {
2224
bool savePlaylist(const char* post);
2325
void takeMallocDog();
2426
void giveMallocDog();
27+
uint32_t max, htmlpos;
28+
bool theend;
2529
#if IR_PIN!=255
2630
bool irRecordEnable;
2731
void irToWs(const char* protocol, uint64_t irvalue);
2832
void irValsToWs();
33+
void chunkedHtmlPage(const String& contentType, AsyncWebServerRequest *request);
2934
#endif
3035
private:
3136
requestType_e request;

yoRadio/options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef options_h
22
#define options_h
33

4-
#define VERSION "0.7.330"
4+
#define VERSION "0.7.355"
55

66
/*******************************************************
77
DO NOT EDIT THIS FILE.

0 commit comments

Comments
 (0)