WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = streamId;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n\r\n");
Serial.println(client.status());
Serial.println(client.available());
while(client.connected()){
n = client.peek();
if(n>0) {
if (n>1024)
n = 1024;
client.read(buf, n);
buf[n] = 0;
Serial.println((char*)buf);
} else {
Serial.print(".");
delay(1000);
}
}
Serial.println();
Serial.println("closing connection");
Using the following server:
const char* host = "icecast.omroep.nl";
const char* streamId = "/3fm-bb-mp3";
This is the result I get:
Connecting to xpto-net
......
WiFi connected
IP address:
192.168.3.249
connecting to icecast.omroep.nl
Requesting URL: /3fm-bb-mp3
4
0
.HTTP/1.0 200 OK
Server: ics2kss.omroep.nl
Date: Fri, 31 Jul 2015 00:15
:53 GMT
Content-Type: audio/mpeg
Cache-Control: no-cache
Expires: Mo
n, 26 Jul 1997 05:00:00 GMT
Pragma: no-cache
icy-br:192
ice-audio-info: bitrate=192
icy-br:192
icy-genre:
Pop
icy-name:3FM Serious Radio
icy-pub:0
icy-url:http://www.3fm.nl
Ì[@¡7Ë
Ú(Eìí
ÉÇÊšh»n�øÔ²
Oþ*÷M&8Üu×èó”úË”ÝÿþçiŸHpNɨ
¦C:Še!îß|å¨Ñ�
µ½mÇÉlêMVµÞé·,³I›æ-gù�HrC¼±þ5lÛãÅöß’§2•|¬Ù€
Š8»Ùz�?‰L0
¯8±ÚH³Üù\y#Ô�«srÝ0€6&©[‰’è<Ÿˆ†¦êàS¾ÓíºvŠ2bÿû´`@ŽF)_OZcr?ǪG¥\Z±}8miíÁ©³só«+èaõZ=$U´‡ïïÁÞ�K±×¬ÿÏ~m{e,&¨œyý^r¾¹óˆj
KH}OËÙè\ûFÕï¬û¶YÕŽ°Ì_�
¥ xâA7U˜eºˆH
”Y¦ÞÕÜÓMåÍï´
ÿŒcýæƒ|R÷Î}3�W¶ÃÜ-OZVÙž[<ÔG0ó½G«Æ¶FúZùs¹ïu
F%&y˜†ÌÌ”ŒTG©(qdD‹.A’9Á
ºžé$Ü@(ÓK‚$µ± HÉz¬°êW
‰hÁCPº&˜¢0‘VÂ_öqÄ”^)l,íôaê·8ŠõFW!«–÷ˆi²>ÉaÑ�€ÿû´`Afí_ΓY{p=':j b\Z½�DláíÁ›h`ö pì’k÷}ÈërT¹AM·¶1ÇX€«Š¬`x§~Îß¼IŒ•‰¸¹’sðœoŽCAÀÿ:ß!Š=Ày{¿‡�{îŸÍ$yØØãæô�
÷sŒó2Þ'–kü<
yxù¾žDí'L@
^€0l¨pîCºÐ!Ƶ>ÿ×vf×Ûh|¨·)“.˜}ú~¥qÛ“’ˆÉŽ®br€ËtË
S)oCN³ôý8UH¥V%ƒxªN…�Ñpºì›Ì;g0fÄqÔÍH$¤
Ñd0„Ø.Ëq::¡œ¨JèÒ~žQ]�[[(¤m’hÌÑ« ¬¿9ÃNÑ$i9V4VWŠÌ6e5/Hù„ÇÇ9mP¼ff«Æ©€
«3v†œñ†¼J�ƒMRøœ1nT°¸Þ/êf:2öŠ
kÿû´`6f `OZ{p@:m\•�>miíÀÞiLS qBŽÛß·U
?ŽE$6(fº‚�ãÇq÷ÜHLnr³(kµNâ9½oñqMVÖqYry–1Ô‘Bصë«æ5í½í3Yß?ƒkÁË›ŒÖœÂÜUl+½‘µìhóYôõÊ}Já¼O
ì
gö„
Ê—ð¼X¢˜�€
s²½]6«°P�
çÑi8f¦ç=4�38ŽÙ¯•ÿû´`7€ž`Ok
4Ál’[š'
\$È…ÔI6#)zÝëZ
îó…gÜ kR¦w–:(µ¤(}û¼ý•Mn륌IoKeïâçŽÅ!ùe6}¾íJ"±oüÓ‰Ü_µ°Æ!—Qe+íËT¹oõ•éd}[Æ
H8m��ˆ_âES¬xª‚À–ÅQ¿ è%oˆÀ¡+Ÿ7ÉÕ}KÆ�8)àp›¤2ê2å”ãD É}Bÿû´`$ŽL`Qk
Æ*šâ
ÙîfÌ“�Ÿ’ûöÀ�O$”HŠB‹›gˆ
€
................................................................................
So after receiving some stream mp3 data I stop receiving data, (no bytes available) no matter how long I wait, but the connection is kept (client.connected() keep returning true). In this example I'm printing the bytes just for testing purposes, I've also made other tests where I just periodically printed the number of bytes received and the problem was the same.
This stream works well with other clients (for example in the browser). It is also one of the streams used in the ESP8266 WebRadio example code using the SDK:
https://github.com/espressif/esp8266_mp ... ser_main.c
Thanks in advance!
Fernando