Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pico2W crashes when sequentially streaming mp3 from URLs #9983

Closed
Labels
@bablokb

Description

@bablokb

CircuitPython version

AdafruitCircuitPython9.2.3on2025-01-17;RaspberryPiPico2Wwithrp2350a

Code/REPL

importtimeimportgcimportboardimportdigitalioimportaudiobusioimportaudiomp3importwifiimportsocketpoolimportsslimportadafruit_requestsclassPlayer:def__init__(self,i2s_pins):self._buffer=bytearray(16384)self._decoder=audiomp3.MP3Decoder("dummy.mp3",self._buffer)self._i2s=audiobusio.I2SOut(*i2s_pins[:3])pool=socketpool.SocketPool(wifi.radio)self._requests=adafruit_requests.Session(pool)# --- play the given webradio-station   ------------------------------------defplay(self,url):gc.collect()whileTrue:try:self._response=self._requests.get(url,timeout=5,headers= {"connection":"close"},stream=True)ifnotself._response:print(f"no response for{url}")time.sleep(1)continueself._decoder.file=self._response.socketself._i2s.play(self._decoder)returnTrueexceptExceptionasex:print(f"play(): exeception:{ex}")returnFalse# --- stop playing   -------------------------------------------------------defstop(self):""" stop playing radio stream """ifself._i2s.playing:try:self._i2s.stop()self._response.socket.close()self._response.close()exceptExceptionasex:print(f"stop(): exeception:{ex}")# --- connect-helper   --------------------------------------------------------defconnect(ssid,passwd):state=wifi.radio.connectedprint(f"  connected:{state}")ifstate:returnfor_inrange(3):try:wifi.radio.connect(ssid,passwd)breakexceptConnectionErrorasex:print(f"{ex}")print(f"  status:{wifi.radio.connected}")ifnotwifi.radio.connected:raiseConnectionError(f"could not connect to{ssid}")# --- main application code   -------------------------------------------------connect("my_ssid","my_password")player=Player(board.GP10# PIN_I2S_BCLKboard.GP11,# PIN_I2S_WSELboard.GP9])# PIN_I2S_DATAURLS= ["http://dispatcher.rndfnk.com/br/br1/obb/mp3/mid","http://dispatcher.rndfnk.com/br/br2/live/mp3/mid","http://dispatcher.rndfnk.com/br/br3/live/mp3/mid","http://dispatcher.rndfnk.com/br/brklassik/live/mp3/mid","http://dispatcher.rndfnk.com/br/br24/live/mp3/mid","http://mdr-284350-0.cast.mdr.de/mdr/284350/0/mp3/high/stream.mp3","http://icecast.ndr.de/ndr/ndrkultur/live/mp3/128/stream.mp3", ]whileTrue:forintervalin [10,5]:forurlinURLS:print(f"free memory before play():{gc.mem_free()}")print(f"playing{url} for{interval}s...")player.play(url)time.sleep(interval)print(f"stopping player")player.stop()time.sleep(1)

Behavior

Automatisches Neuladen ist aktiviert. Speichere Dateien einfach über USB, um sie auszuführen, oder gib REPL ein, um sie zu deaktivieren.main.py Ausgabe:  connected: False  status: Truefree memory before play(): 313104playing http://dispatcher.rndfnk.com/br/br1/obb/mp3/mid for 10s...stopping playerfree memory before play(): 284752playing http://dispatcher.rndfnk.com/br/br2/live/mp3/mid for 10s...stopping playerfree memory before play(): 282480playing http://dispatcher.rndfnk.com/br/br3/live/mp3/mid for 10s...[15:31:46.853] Disconnected

Description

The program automatically cycles through a number of web-streams from internet radio (in the real application the user presses buttons to switch stations). After a few URLs, the Pico2W just disconnects and needs a hard reset for a restart. Behavior is random, sometime it fails after three streams, sometimes later.Switching streams seems to be the problem, playing a single stream for an extended time works without problems for all of the example URLs.

Note that you don't need real I2S hardware to reproduce the error. Also, the program works fine on an ESP32-S3.

Some speculations: maybe the network-stack of the Pico2W does not cleanup resources and fails after a while. Or it produces illegal data during close and this trips the MP3Decoder.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp