witnessmenow / spotify-api-arduino

Arduino library for integrating with the Spotify Web-API (Does not play music)
MIT License
182 stars 32 forks source link

Crashes when it's time to Refresh the Access Token #19

Closed MythicalForce closed 3 years ago

MythicalForce commented 3 years ago

This the the Serial Monitor

/v1/me/player/currently-playing?market=NO
Status Code: 200
Closing client
[ #1 ][SPOTIFY][LOOP] triggered!
[ #2 ][SPOTIFY][CHECK][ISPLAYING] True
[ #3 ][SPOTIFY][SET][CURRENTLYPLAYING] The Real Slim Shady

/v1/me/player/currently-playing?market=NO
Status Code: 200
Closing client
[ #1 ][SPOTIFY][LOOP] triggered!
[ #2 ][SPOTIFY][CHECK][ISPLAYING] True
[ #3 ][SPOTIFY][SET][CURRENTLYPLAYING] The Real Slim Shady

/v1/me/player/currently-playing?market=NO
Status Code: 200
Closing client
[ #1 ][SPOTIFY][LOOP] triggered!
[ #2 ][SPOTIFY][CHECK][ISPLAYING] True
[ #3 ][SPOTIFY][SET][CURRENTLYPLAYING] The Real Slim Shady

/v1/me/player/currently-playing?market=NO
Refresh of the Access token is due, doing that now.

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400014e8  PS      : 0x00060230  A0      : 0x800f3200  A1      : 0x3ffb1590  
A2      : 0x00496972  A3      : 0x00496970  A4      : 0x000000ff  A5      : 0x0000ff00
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x462d4100  A9      : 0x3ffb1860  
A10     : 0x00000003  A11     : 0x00060223  A12     : 0x00060220  A13     : 0x00000000  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00496970  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

ELF file SHA256: 0000000000000000

Backtrace: 0x400014e8:0x3ffb1590 0x400f31fd:0x3ffb15a0 0x400f1349:0x3ffb18b0 0x400d1bca:0x3ffb1970 0x400d1d2d:0x3ffb1db0 0x400d1dad:0x3ffb1dd0 0x400d258b:0x3ffb1f10 0x400d25fa:0x3ffb1f80 0x400d71b8:0x3ffb1fb0 0x4008992a:0x3ffb1fd0
  #0  0x400014e8:0x3ffb1590 in ?? ??:0
  #1  0x400f31fd:0x3ffb15a0 in _svfprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:1529
  #2  0x400f1349:0x3ffb18b0 in sprintf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/sprintf.c:644
  #3  0x400d1bca:0x3ffb1970 in ArduinoSpotify::refreshAccessToken() at src/ArduinoSpotify.cpp:247
  #4  0x400d1d2d:0x3ffb1db0 in ArduinoSpotify::checkAndRefreshAccessToken() at src/ArduinoSpotify.cpp:247
  #5  0x400d1dad:0x3ffb1dd0 in ArduinoSpotify::getCurrentlyPlaying(char const*) at src/ArduinoSpotify.cpp:247
  #6  0x400d258b:0x3ffb1f10 in Spotify::loop() at include/mySpotify.h:102
  #7  0x400d25fa:0x3ffb1f80 in loop() at src/main.cpp:31
  #8  0x400d71b8:0x3ffb1fb0 in loopTask(void*) at C:\users\krist\.platformio\packages\framework-arduinoespressif32\cores\esp32/main.cpp:23
  #9  0x4008992a:0x3ffb1fd0 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_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:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
*** ESP32-HUB75-MatrixPanel-I2S-DMA: Memory Allocations Complete ***
Total memory that was reserved: 14 kB.
... of which was used for the DMA Linked List(s): 6 kB.
Heap Memory Available: 313896 bytes total. Largest free block: 113792 bytes.
General RAM Available: 245556 bytes total. Largest free block: 113792 bytes.
[WIFI][STATUS] Connecting to WiFi..
[WIFI][STATUS] Connecting to WiFi..
[WIFI][STATUS] Connecting to WiFi..
[WIFI][STATUS] Connecting to WiFi..
[WIFI][STATUS] Connecting to WiFi..
[WIFI][STATUS] Connected
[DNS][NAME] Matrix16x32
grant_type=refresh_token&refresh_token=AQDEDjdcfKXdlEbipT96ipLNUd7Z5POAsIZCmT_xxGs_LlSp1cbvKiwLDYxAoCfgSJKVyKzOe5hYZ9ROE9I5djTvGMD4Kj36NiaAtsKomNnopM8y5yF7zXYHGiGvp99BVg4&client_id=02a6ad0c66434cf5b5cd792f59aeee0f&client_secret=dbf2688de2c147c695564070cc4dc30a
Status Code: 200
status Code200
Closing client
/v1/me/player/currently-playing?market=NO
Status Code: 200
Closing client
[ #1 ][SPOTIFY][LOOP] triggered!
[ #2 ][SPOTIFY][CHECK][ISPLAYING] True
[ #3 ][SPOTIFY][SET][CURRENTLYPLAYING] The Real Slim Shady
[ #4 ][SPOTIFY][CHECK][NEWSONG][OR][SAMESONG] False/True
/v1/me/player/currently-playing?market=NO
Status Code: 200
Closing client

And this is what my main loop looks like

void loop()
{
  if (millis() > requestDueTime)
  {
    Spotify::loop();

    if (Spotify::isPlaying() == true)
    {

      #ifdef SPOTIFY_DEBUG
          Serial.println("[ #2 ][SPOTIFY][CHECK][ISPLAYING] True");
      #endif

      String currentlyPlaying = String(Spotify::currentlyPlaying.trackName);

      #ifdef SPOTIFY_DEBUG
          Serial.print("[ #3 ][SPOTIFY][SET][CURRENTLYPLAYING] ");
          Serial.println(currentlyPlaying);
      #endif

      if (currentlyPlaying != Spotify::lastPlayedSong || Spotify::SpotifyPaused == true)
      {

        #ifdef SPOTIFY_DEBUG
            Serial.println("[ #4 ][SPOTIFY][CHECK][NEWSONG][OR][SAMESONG] False/True");
        #endif

        Matrix::clear();
        Matrix::drawSpotifyLogo();
        Matrix::writeText(18, 0, dma_display->color444(0,0,15), Spotify::currentlyPlaying.firstArtistName);
        Matrix::writeText(18, 8, dma_display->color444(0,15,0), Spotify::currentlyPlaying.trackName);
        Spotify::lastPlayedSong = currentlyPlaying;
        Spotify::SpotifyPaused = false;
      }
      Matrix::drawOnce = false;
    }
    else
    {
      if (Matrix::drawOnce == false)
      {

        #ifdef SPOTIFY_DEBUG
            Serial.println("[ #5 ][SPOTIFY][CHECK][ISPLAYING] False");
        #endif

        Matrix::clear();
        Matrix::drawSpotifyLogo();
        Matrix::writeText(18, 0, dma_display->color444(15,0,0), (char *)"Spotify is not playing!");
        Matrix::writeText(18, 8, dma_display->color444(15,15,15), (char *)"Time 4 silent party!");
        Matrix::drawOnce = true;
        Spotify::SpotifyPaused = true;
      }
    }
    requestDueTime = millis() + delayBetweenRequests;
  }
}
Tpow99 commented 3 years ago

I had the same problem, this repo is a little outdated at this time. I had to use a bearssl WiFi client and specifically set it to insecure in order to establish a connection with the Spotify endpoint manually using an http object, then send the requests myself. This repo is an awesome guide on how but some of the logistics are outdated

witnessmenow commented 3 years ago

Will set up a test for for the refresh token when I get a chance, I believe that was working before though.

It's weird in the logs that the line being pointed to is 247 for all of these:

  #3  0x400d1bca:0x3ffb1970 in ArduinoSpotify::refreshAccessToken() at src/ArduinoSpotify.cpp:247
  #4  0x400d1d2d:0x3ffb1db0 in ArduinoSpotify::checkAndRefreshAccessToken() at src/ArduinoSpotify.cpp:247
  #5  0x400d1dad:0x3ffb1dd0 in ArduinoSpotify::getCurrentlyPlaying(char const*) at src/ArduinoSpotify.cpp:247

when Line 247 is not a sprintf either (which the next line of the stack trace indicates it hit)

https://github.com/witnessmenow/arduino-spotify-api/blob/master/src/ArduinoSpotify.cpp#L247

@Tpow99 , which platform are you using?

Tpow99 commented 3 years ago

I am using an esp8266 node mcu

witnessmenow commented 3 years ago

What version of esp8266 core are you using? Bearssl one is the default one for years now, I'm also pretty sure all the examples include a fingerprint (which can be used instead of setting insecure), but maybe that's expired by now, which would be a sperate issue

On Thu 1 Apr 2021, 07:01 Tpow99, @.***> wrote:

I am using an esp8266 node mcu

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/witnessmenow/arduino-spotify-api/issues/19#issuecomment-811666306, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAL5PQQHPT62TWROZWADHELTGQD4ZANCNFSM42EUHE5A .

Tpow99 commented 3 years ago

originally, I did switch to the set insecure because the fingerprint was expired. This is when I started to come across more problems in the development. I am on the esp 2.6.3 release. I often get a connection failed when I use your methods(Which are my preferred way) so I started rewriting them. Generally, I receive error code -1 when attempting to refresh. I haven't updated your repo in a while as I took a break from that project.

Edit: On my version of the code using your repo, I am able to create a temporary access token, then my code fails on the following request to the /api/token endpoint. This is the requestAccessTokens call in your code repo

witnessmenow commented 3 years ago

I have made some improvements to the memory usage in #21 which may solve this issue. I have a display setup now so I can try keep an eye on if it happens.

If you want to try updating to the latest version (here: https://github.com/witnessmenow/arduino-spotify-api/tree/getImageBuffer) @MythicalForce and see if it helps that would be great.

PacuFTW commented 3 years ago

originally, I did switch to the set insecure because the fingerprint was expired. This is when I started to come across more problems in the development. I am on the esp 2.6.3 release. I often get a connection failed when I use your methods(Which are my preferred way) so I started rewriting them. Generally, I receive error code -1 when attempting to refresh. I haven't updated your repo in a while as I took a break from that project.

Edit: On my version of the code using your repo, I am able to create a temporary access token, then my code fails on the following request to the /api/token endpoint. This is the requestAccessTokens call in your code repo

Hey, I have the -1 error code too. Is there a fix you found for it yet? I need this for my class assignment lol

Edit: Linking my thread about this issue here too for easier accessibility.

witnessmenow commented 3 years ago

I have no seen this issue while I'm using it. The branch with the updated code has been merged to master. Re-open the issue again if you see the problem again.