witnessmenow / spotify-api-arduino

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

Strange behaviour of player controls function #69

Open roogue opened 5 months ago

roogue commented 5 months ago

Hi I am new to C++ language and this library. So far this library works for my project, however, the spotify.play() function will always fail with the following message.

/v1/me/player/play
api.spotify.com
[ 11307][E][ssl_client.cpp:37] _handle_error(): [send_ssl_data():382]: (-80) UNKNOWN ERROR CODE (0050)
Failed to send request

The strange thing is, the request was actually sent successfully, and my music was played as intended.

Additional Info:

roogue commented 5 months ago

~Update: I met the same issue even if I ran the exact same code from your getRefreshToken.ino example. I am doubting maybe it is the behavior of the WifiClientSecure library.~

Connected to xxx wifi
IP address: 192.168.x.xxx
MDNS responder started
HTTP server started
grant_type=authorization_code&code=xxxx
accounts.spotify.com
Status: HTTP/1.0 200 OK
HTTP Version: HTTP/1.0
Status Code: 200
status Code200
[  5379][E][ssl_client.cpp:37] _handle_error(): [data_to_read():361]: (-80) UNKNOWN ERROR CODE (0050)

~Edit: It happens randomly too, sometimes it behaves as intended.~

roogue commented 5 months ago

I think I found the problem, the issue occurred in SpotifyArduino.cpp lines 86, under makeRequestWithBody() function.

Somehow it happened when an empty body was printed with client->print(body);

I made a tad bit changes to the code and everything seems working again,

From

client->print(body);

To

if (strlen(body) == 0)
{
    client->println();
}
else
{
    client->print(body);
}

Where I use client->println(); instead when printing an empty body.