Hello,
I used a very simple WiFi client to connect to an internet radio stream on a ESP8266 Node V3 board.
I have a big problems with the data reception reliability:
- if I try to receive the data as quick as possible (main loop basically containing if client connected and if client available then read all data and store in a ring buffer) then I read very within 200 ms about 20kB of data, which, however, does not seem to be ok.
I see that is not ok because I detect the meta interval info from the header and I parse the meta info on each interval from the stream.
In this error case the meta section in the received stream occurs in 200 ms interval, and not in 1..1.5 seconds interval as usual. And after receiving 3...5 times this meta info it losses the sync within the stream (means that the chunk meta number after counting the interval has nonsense values (larger than 100). So I have the feeling that the read data from the client is old data repeated.
I found out that if I insert some delay in the reception part (where I read out the data from client) then the thing works, meaning that meta info comes regularly in the specified intervals and losses sync only when the ring buffer overrun (read out from the buffer is slower than the writing to the buffer).
To fix this thing I finally ended up with implementing a dynamic delay on the WIFi client read-out side dependent on the ring buffer fill status. And it works like a charm, nice continuous sound, no buffer overflow, and no missed metadata within 1 hour test period.
So my question would be: is this kind of behavior known? I mean no one had any problems with such kind of setup before?
I appreciate any reply / hint / advice / comment.
ESP8266 Internet Radio unreliable WiFi data
-
- Posts: 4
- Joined: Sun Feb 11, 2024 8:57 pm
-
- Posts: 4
- Joined: Sun Feb 11, 2024 8:57 pm
Re: ESP8266 Internet Radio unreliable WiFi data
Just for those interested:
I have searched more about the techniques how to best consume streams, and I figured out that the solution is to read from internet client only if the decoder (VS1003 in my case) needs data.
So now I fill up the buffer, start streaming, and read from client as long as there is space in buffer.
This way the buffer can be always be filled to max and I read from client only if space is available (due to decoder read out).
I have searched more about the techniques how to best consume streams, and I figured out that the solution is to read from internet client only if the decoder (VS1003 in my case) needs data.
So now I fill up the buffer, start streaming, and read from client as long as there is space in buffer.
This way the buffer can be always be filled to max and I read from client only if space is available (due to decoder read out).
Re: ESP8266 Internet Radio unreliable WiFi data
Without seeing your code, I can't be sure... but you can't just continuously read in a loop and not return control to the processor. Assuming you are using the Arduino IDE coding style, you have to return control from the loop() in a timely manner. This is well documented, so yes, it is known. The 8266 is a single threaded processor, but you have to let the underlying WiFi code process the TCP/IP packets so that you can retrieve them. On some implementations, the delay() function (under the covers) actually returns control to the processor to let it do its work.
Re: ESP8266 Internet Radio unreliable WiFi data
Everybody has obsolete smartphones in their drawers. They are perfect to listen to radio streams.stevestrong wrote: ↑Mon Feb 12, 2024 8:44 amI have searched more about the techniques how to best consume streams...
No need to tease an ESP8266 for that.
-
- Posts: 4
- Joined: Sun Feb 11, 2024 8:57 pm
Re: ESP8266 Internet Radio unreliable WiFi data
I am aware of insertingInq720 wrote: ↑Mon Feb 12, 2024 12:09 pmWithout seeing your code, I can't be sure... but you can't just continuously read in a loop and not return control to the processor. Assuming you are using the Arduino IDE coding style, you have to return control from the loop() in a timely manner. This is well documented, so yes, it is known. The 8266 is a single threaded processor, but you have to let the underlying WiFi code process the TCP/IP packets so that you can retrieve them. On some implementations, the delay() function (under the covers) actually returns control to the processor to let it do its work.
Code: Select all
yield();
The Arduino loop is fragmented and has at least two sections, none of them is blocking for more than needed.
One of the section is to read data from wifi client and store it into the ring buffer.
The error case happens when I neglect the buffer state and just read out data from Wifi client continuously as long as data available. Each time I read out about ~1500 byes.
Of course I continue with other sections of the loop when this is done.
But when I do not slow down this read out rate, then the received data is somehow broken, as I described above. This is the main point.
Can happen that the server will send me this data when I consume it too quickly?
-
- Posts: 4
- Joined: Sun Feb 11, 2024 8:57 pm
Re: ESP8266 Internet Radio unreliable WiFi data
I am doing this not because there are no other (better) ways to accomplish that, but because I want to do it .
The main reason is that I have a portable broken Internet Radio device, and want to repair it by replacing the main controller.
Who is online
Users browsing this forum: No registered users and 5 guests