logo elektroda
logo elektroda
X
logo elektroda

[Solved] Creating an internet radio player: Restart ESP at audio.connecttohost -

speedy9 1422 23
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 20731606
    speedy9
    Helpful for users
    I am trying to make a simple internet radio player. There is quite a lot on the internet about it. I, however, am struggling with the problem.
    Environment: Arduino IDE 2.2.1
    Board: WEMOS LOLIN32 LITE clone
    Audio board: PCM5102A
    Connections:
    Connection diagram between ESP32 Lolin32 Lite board and PCM5102A audio module
    Audio library: https://github.com/schreibfaul1/ESP32-audioI2S/tree/master

    
    #include "Audio.h"
    #include "WiFi.h"
    #include "Arduino.h"
    
    #define I2S_DOUT 25
    #define I2S_BCLK 27
    #define I2S_LRC 26
    
    String ssid = "*********";
    String password = "*******";
    
    Audio audio;
    
    void setup(){
      Serial.begin(115200);
      WiFi.disconnect();
      WiFi.mode(WIFI_STA);
      WiFi.begin(ssid.c_str(),password.c_str());
      Serial.println("Connected");
      Serial.println(WiFi.localIP());
      Serial.print("RRSI: ");
      Serial.println(WiFi.RSSI());
      audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
      audio.setVolume(15);
      audio.connecttohost("http://stream.open.fm/378?type=.aac");  
      Serial.println ("Connect do stream");
    }
    void loop()
    {
      audio.loop();
    }
    


    Code compiles and uploads, but program crashes on line audio.connecttohost("http://stream.open.fm/378?type=.aac"); causing ESP to reboot:
    Screenshot showing a Guru Meditation Error message in the console while running code in Arduino IDE.

    Any suggestions what could be wrong?

    I tried another station, MP3 format, effect always the same. I have uploaded the program to a second ESP board, with the same result[/code].
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 20731691
    JacekCz
    Level 42  
    Kernel panic ... there are no easy recipes for this, e.g. if the author didn't take care of something / overdid it

    Cross-tests can be advised, e.g. run other addresses / request other formats
  • #3 20731694
    speedy9
    Helpful for users
    JacekCz wrote:
    Cross-trials can be advised, e.g. run other addresses / request other formats
    Tried, does not work.
  • #4 20731698
    JacekCz
    Level 42  
    Traces on github indicate various "corrupt" that he corrected. And as one corrupt was, statistically others are also likely.

    Code is "hacky", bad to read, assembler insertions .... "write only" type code

    You have a belief from INDEPENDENT sources that the author can handle it ?
  • #5 20731710
    speedy9
    Helpful for users
    I have no conviction. I need a small player for one internet station. It doesn't have to be this library. Something else tried and tested will also be ok. Descriptions on the internet directed to this one, hence its use.
  • #6 20731712
    JacekCz
    Level 42  
    speedy9 wrote:
    Descriptions on the internet directed to this one,


    You know, millions of flies can't be wrong ....

    Added after 3 [minutes]:

    Are you able to afford (financially and mentally) to say goodbye to ESP in favour of Raspberry ?

    If I were to do something similar, I would have more confidence in the more high-level Linux-Raspberry code, I would believe that it is better tested, than in bare metal.

    (statement by someone completely inactive in these areas)
  • ADVERTISEMENT
  • #7 20731766
    speedy9
    Helpful for users
    JacekCz wrote:
    Are you able to afford (financially and mentally) to say goodbye to ESP in favour of Raspberry ?

    Finances have little to do here rather: https://botland.com.pl/modulus-and-kits-raspb...-raspberry-pi-zero-w-basic-5903351240109.html
    The bare RPi Zero W costs well <100£ without looking.

    But the ESP32 will handle the same and is small and takes 2-3 times less power. It also costs ~£12 in total. So much so that neither HDMI nor LCD support is unnecessary for me.
  • ADVERTISEMENT
  • #8 20731860
    JacekCz
    Level 42  
    speedy9 wrote:
    But ESP32 will handle the same and is small and takes 2-3 times less power.


    Shame you didn't answer the second part of the question.

    Of course ESC32 hardware is lighter.
    But the supply of trusted code is much smaller in my opinion.
  • #9 20732292
    speedy9
    Helpful for users
    JacekCz wrote:
    But the supply of trusted code according to me much less.
    This I do not know, because I have no comparison. I have no experience with either platform. Linux in any case can be a pain to use. I have a NAS running on OpenMediaVault (Debian) and it has already given me a healthy scare a few times.
  • #10 20732604
    JacekCz
    Level 42  
    speedy9 wrote:
    JacekCz wrote:
    But the supply of trusted code in my opinion much less.
    I don't know, because I have no comparison. I have no experience with either platform. Linux in any case can be a pain to use. I have a NAS running on OpenMediaVault (Debian) and it has already annoyed me a few times.


    You were annoyed by Linux (Debian) or some software running on it.
    You yourself gave an example that there is an open market for solutions (market not only in the sense of the word "trade", but also in the sense of "where to discuss"). There are certainly inferior ones, but there is generally a choice.
  • Helpful post
    #11 20732633
    Menuet
    Level 19  
    Hi,
    The library the author wants to use works, but is capricious :) It can be tamed. I used to fiddle with it and it was ok, in fact (probably) the best use of it was in the project: M5StickC_WebRadio . There is also bluetooth support, which can be easily knocked out, I also omit the user interface, but as a basis for reworking the code is ok.

    Another project, which I recommend, works reliably, nothing needs to be reworked, configuration via WWW, is KaRadio32 . You can even upload a ready-made binary and it just works.

    In terms of using Raspberry and Linux for such a task, it's ok, it can be done, but I'm most annoyed by the boot time of such a system (in the basic version, without slimming down, because that's a different topic). As an internet radio, however, it's probably better to have something that, when switched on, will start playing after a few, a couple of seconds and not wait for e.g. a minute :)

    Greetings,
    Menuet

    Edit:
    When it comes to the author's code, it seems to me that it tries to start playback a bit too quickly when connecting to WiFi. I would add an expectation for this:
    WiFi.begin(ssid.c_str(),password.c_str());
    while (WiFi.status() != WL_CONNECTED) delay(100);

    Maybe it will help :)


    Apparently from the terminal it can be seen that it connects first and has an IP, but I would check - it varies with libraries on the Arduino :) As previous contributors have written, the quality of such code leaves a lot to be desired...
  • #12 20732693
    speedy9
    Helpful for users
    In the uploaded code I added a delay anyway. A total of 6s before connecting to the stream. My code for debugging also prints out the text on the terminal after each of these lines and has a delay(2000) after the text is written out.
    audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
    audio.setVolume(15);
    Hence I know that it "crashes" immediately after going to audio.connecttohost
    In the while loop I also had the LED flashing with delay(1000) until it connects to WiFi.
    It doesn't do anything. When I comment out audio.connecttohost it connects to WiFi and holds the connection without rebooting. So clearly it has a problem with this Audio.h library
    I have already reinstalled the Arduino IDE deleting the Temp and libraries and downloading it again. Nothing has helped. Is the board to blame (I have two of the same, both new)?

    Thanks for the tip on KaRadio32. I'll check it out. But with LOLIN Lite, I don't think it's enough to simply upload the ready-made binaries. Different GPIO numbering from ego what I took a quick look at. I might give it a try at the weekend.
  • Helpful post
    #13 20732864
    Menuet
    Level 19  
    I won't say that I'm a bit curious about the problem ;)

    Below is the code that works normally with me, lets stream. Compiled in Arduino IDE (I usually use Platformio, there it is somehow easier ;) )

    #include "Audio.h"
    #include "WiFi.h"
    #include "Arduino.h"
    
    #define I2S_DOUT 25
    #define I2S_BCLK 27
    #define I2S_LRC 26
    
    String ssid = "TestNetwork";
    String password = "NetworkTest";
    
    Audio audio;
    
    
    void setup(){
      Serial.begin(115200);
      WiFi.disconnect();
      WiFi.mode(WIFI_STA);
      WiFi.begin(ssid.c_str(),password.c_str());
      while (WiFi.status() != WL_CONNECTED) delay(100);
      Serial.println("Connected");
      Serial.println(WiFi.localIP());
      Serial.print("RRSI: ");
      Serial.println(WiFi.RSSI());
      audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
      audio.setVolume(15);
      audio.connecttohost("http://stream.open.fm/378?type=.aac");  
      Serial.println ("Connect do stream");
    }
    void loop()
    {
      audio.loop();
    }
    
    void audio_info(const char *info){
        Serial.println(info);
    }



    and console result:

    ets Jun  8 2016 00:22:57
    
    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:
    0x00
    mode:DIO, clock div:1
    load:0x3fff0018,len:4
    load:0x3fff001c,len:1216
    ho 0 tail 12 room 4
    load:0x40078000,len:10944
    load:0x40080400,len:6388
    entry 0x400806b4
    Connected
    192.168.1.102
    RRSI: -47
    Connect to new host: "http://stream.open.fm/378?type=.aac"
    PSRAM not found, inputBufferSize: 14399 bytes
    buffers freed, free Heap: 215896 bytes
    Connection has been established in 52 ms, free Heap: 214584 bytes
    Connect do stream
    icy-name: 378 (icy-br:48)
    AACDecoder has been initialized, free Heap: 188044 bytes , free sta
    ck 6360 DWORDs
    stream ready
    syncword found at pos 0
    Channels: 1
    SampleRate: 22050
    BitsPerSample: 16
    BitRate: 44444
    AAC HeaderFormat: ADTS
    AAC Codec: MPEG-4 LowComplexity
    VBR recognized, audioFileDuration is estimated
    StreamTitle=''
    


    For the possibility of testing your hardware, a compiled file with this exact code is also attached. WiFi is a hotspot you can make in your phone :)

    With regard to KaRadio32, it will work with your board. The default pins for I2S are described on Github.

    Greetings,
    Menuet
  • ADVERTISEMENT
  • #14 20732877
    speedy9
    Helpful for users
    Well, it's interesting to see what this is all about. Tell me more how I should upload the BIN to the board via the Arduino IDE?
    How about that?
    Screenshot of Windows PowerShell with a command to upload a BIN file to an ESP8266 board using Arduino IDE. .
  • #15 20732911
    inot
    Level 37  
    This can be done as explained in the video below: Link .
  • #16 20732998
    speedy9
    Helpful for users
    Well, it's the same as far as I can see.
  • #17 20733033
    inot
    Level 37  
    speedy9 wrote:
    the same thing as far as I can see
    Like that. The conclusion is that you thought right.
  • #18 20733380
    speedy9
    Helpful for users
    Menuet wrote:
    For the possibility of testing your hardware, a compiled file with this exact code is also attached. You can make a WiFi hotspot on your phone

    I uploaded it and.... it works! I made a new sketch, pasted your code, compiled, uploaded to ESP and.... also works.
    I compile my code and it doesn't work (reboot loop), compile and play yours again and it works.
    The two sketches differ in total only in the presence of:
    void audio_info(const char *info){
        Serial.println(info);
    }
    Why doesn't my program work? I have a fresh Arduino IDE and only installed this Audio library from the ZIP file.
  • #19 20733397
    inot
    Level 37  
    The variable info probably contains an invalid "string".
  • #20 20733407
    speedy9
    Helpful for users
    But that's nothing to do with it, because that part is not in my program. It is in the program from @Menuet which works
  • #21 20733416
    inot
    Level 37  
    I thought it was the other way around.
  • Helpful post
    #22 20733418
    Menuet
    Level 19  
    It seems to me, but I am not sure, that the creator of the library did not fully anticipate not using the debug of his library. If it's an empty function then it should work, but if it's undefined (In the library it shows as weak) then there's some problem with the buffer to which the texts are written.

    inot wrote:
    I thought it was the other way around.
    I suggest to read with more comprehension, because exactly the Author described it now :) .
  • #23 20733459
    inot
    Level 37  
    Menuet wrote:
    as the author has now described exactly that
    You are right, but I was over-suggesting that the error described by the author is typical of the buffer text playback problem.
  • #24 20734190
    speedy9
    Helpful for users
    Adding the function at the end of the programme:
    void audio_info(const char *info){
        Serial.println(info);
    }

    resolved the problem.

Topic summary

The discussion revolves around creating a simple internet radio player using an ESP32-based board (WEMOS LOLIN32 LITE clone) and the PCM5102A audio board. The user encounters issues with the audio.connecttohost function, leading to a reboot loop. Various responses suggest that the library being used is unreliable and may contain bugs. Alternatives like KaRadio32 and M5StickC_WebRadio are recommended for more stable performance. The user ultimately resolves their issue by adding a function to handle audio information, which was causing the program to crash. The conversation highlights the trade-offs between using ESP32 and Raspberry Pi for such projects, with considerations of power consumption and code reliability.
Summary generated by the language model.
ADVERTISEMENT