1010char ssid[] = SECRET_SSID; // your network SSID (name)
1111char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
1212
13+ // #define DEBUG
1314
14- // http://ice1.somafm.com/u80s-128-mp3
15- const char *host = " ice1.somafm.com" ;
16- const char *path = " /u80s-128-mp3" ;
15+ // SOMA FM Radio 80's http://ice1.somafm.com/u80s-128-mp3
16+ // const char *host = "ice1.somafm.com";
17+ // const char *path = "/u80s-128-mp3";
1718// const char *path = "/doomed-128-mp3";
18- int httpPort = 80 ;
19+ // int httpPort = 80;
20+
21+ // WMBR radio http://wmbr.org:8000/med
22+ const char *host = " wmbr.org" ;
23+ const char *path = " /med" ;
24+ int httpPort = 8000 ;
1925
2026// These are the pins used
2127#define VS1053_RESET -1 // VS1053 reset pin (not used!)
2228#define VS1053_CS 7 // VS1053 chip select pin (output)
2329#define VS1053_DCS 6 // VS1053 Data/command select pin (output)
2430#define VS1053_DREQ 3 // VS1053 Data request, ideally an Interrupt pin
31+ #define ESP_CS 10
32+ #define ESP_READY 9
33+ #define ESP_RESET 8
34+ #define ESP_GPIO0 -1
35+
2536
2637Adafruit_VS1053 musicPlayer = Adafruit_VS1053(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ);
2738
@@ -30,20 +41,25 @@ WiFiClient client;
3041
3142int lastvol = 30 ;
3243
33- #define BUFFER_SIZE 1500
44+ #if defined (__AVR__)
45+ #define BUFFER_SIZE 128
46+ #else
47+ #define BUFFER_SIZE 1500
48+ #endif
49+
3450CircularBuffer<uint8_t , BUFFER_SIZE> buffer;
3551
3652void setup () {
3753 Serial.begin (115200 );
3854 while (!Serial);
3955 delay (100 );
4056
41- Serial.println (" \n\n Adafruit VS1053 Feather WiFi Radio" );
57+ Serial.println (F ( " \n\n Adafruit VS1053 Feather WiFi Radio" ) );
4258
4359 /* ************************ INITIALIZE MP3 Shield */
4460 if (! musicPlayer.begin ()) { // initialise the music player
4561 Serial.println (F (" Couldn't find VS1053, do you have the right pins defined?" ));
46- while (1 ) delay (10 );
62+ // while (1) delay(10);
4763 }
4864
4965 Serial.println (F (" VS1053 found" ));
@@ -55,26 +71,27 @@ void setup() {
5571 // don't use an IRQ, we'll hand-feed
5672
5773 /* ************************ INITIALIZE WIFI */
58- Serial.print (" Connecting to SSID " ); Serial.println (ssid);
74+ WiFi.setPins (ESP_CS, ESP_READY, ESP_RESET, ESP_GPIO0);
75+ Serial.print (F (" Connecting to SSID " )); Serial.println (ssid);
5976 WiFi.begin (ssid, pass);
6077
6178 while (WiFi.status () != WL_CONNECTED) {
6279 delay (500 );
6380 Serial.print (" ." );
6481 }
65- Serial.println (" WiFi connected" );
66- Serial.println (" IP address: " ); Serial.println (WiFi.localIP ());
82+ Serial.println (F ( " WiFi connected" ) );
83+ Serial.println (F ( " IP address: " ) ); Serial.println (WiFi.localIP ());
6784
6885 /* ************************ INITIALIZE STREAM */
69- Serial.print (" Connecting to " ); Serial.println (host);
86+ Serial.print (F ( " Connecting to " ) ); Serial.println (host);
7087
7188 if (!client.connect (host, httpPort)) {
72- Serial.println (" Connection failed" );
89+ Serial.println (F ( " Connection failed" ) );
7390 while (1 );
7491 }
7592
7693 // We now create a URI for the request
77- Serial.print (" Requesting URL: " ); Serial.println (path);
94+ Serial.print (F ( " Requesting URL: " ) ); Serial.println (path);
7895
7996 // This will send the request to the server
8097 client.print (String (" GET " ) + path + " HTTP/1.1\r\n " +
@@ -84,16 +101,19 @@ void setup() {
84101
85102
86103void loop () {
87- Serial.print (" Client Avail: " ); Serial.print (client.available ());
88- Serial.print (" \t Buffer Avail: " ); Serial.println (buffer.available ());
104+ #if defined(DEBUG)
105+ Serial.print (F (" Client Avail: " )); Serial.print (client.available ());
106+ Serial.print (F (" \t Buffer Avail: " )); Serial.println (buffer.available ());
107+ #endif
89108
90109 // Prioritize reading data from the ESP32 into the buffer (it sometimes stalls)
91110 while (client.available () && buffer.available ()) {
92111 uint8_t minibuff[BUFFER_SIZE];
93112
94113 int bytesread = client.read (minibuff, buffer.available ());
95- Serial.print (" Client read: " ); Serial.println (bytesread);
96-
114+ #if defined(DEBUG)
115+ Serial.print (F (" Client read: " )); Serial.println (bytesread);
116+ #endif
97117 for (int i=0 ; i<bytesread; i++) {
98118 buffer.push (minibuff[i]); // push every byte we read
99119 }
@@ -105,7 +125,9 @@ void loop() {
105125 uint8_t mp3buff[32 ]; // vs1053 likes 32 bytes at a time
106126
107127 int byteswrite = min (32 , buffer.size ());
108- Serial.print (" MP3 write: " ); Serial.println (byteswrite);
128+ #if defined(DEBUG)
129+ Serial.print (F (" MP3 write: " )); Serial.println (byteswrite);
130+ #endif
109131
110132 // push to mp3
111133 for (int i=0 ; i<byteswrite; i++) {
0 commit comments