0 votes
in ESP8266 WiFi Color Kit by (160 points)

Hi,

I'm having trouble getting the Spotify Remote to work. I've followed the guide, and the Spotify unique Client ID and Client Secret are in place at the respective variables in settings.h. BUT, after uploading the sketch, calibrating the touch screen and accessing http://esp8266.local/ the TFT just shows the splash screen and "Please define clientId and clientSecret". But those ARE defined in settings.h, so I'm out of ideas of what to do. The serial monitor shows this:

Body starts now

start document

start document

HREF: 

--------Response Code: 400

--------Free mem: 24672

Requesting URL: GET /v1/me/player/currently-playing HTTP/1.1

Host: api.spotify.com

Authorization: Bearer 

Connection: close

HTTP/1.1 400 Bad Request

HTTP Code: 400

Content-Type: application/json

Content-Type: application/json

WWW-Authenticate: Bearer realm="spotify", error="invalid_request", error_description="Only valid bearer authentication supported"

Access-Control-Allow-Origin: *

Access-Control-Allow-Headers: Accept, Authorization, Origin, Content-Type, Retry-After

Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE, PATCH

Access-Control-Allow-Credentials: true

Access-Control-Max-Age: 604800

Content-Length: 99

Date: Tue, 08 Jan 2019 20:05:04 GMT

Via: 1.1 google

Alt-Svc: clear

Connection: close

So there's obviously an identification problem, but I just can't see what I've done wrong. Any ideas?

Regards,

Thorleif 

by (19.9k points)
I don't dare (yet) to post an answer but the key here seems to be the "Authorization: Bearer " in your serial output. Did you notice that the token is missing here? It should be "Authorization: Bearer <some-long-token-string-here>". The proof for that is here: https://github.com/ThingPulse/esp8266-spotify-remote/blob/master/SpotifyClient.cpp#L61. That access token should have been assigned to your app instance during startup in which `SpotifyClient::getToken` is called.

I propose you start from scratch (app pairing etc.), collect the serial console output into a file that you can make available to us somewhere for download. In the Arduino IDE set Tools>Erase Flash to "All Flash Contents" to completely wipe the device file system.
by (160 points)
Thanks for your reply. I will give it at try this evening and start all over from scratch, erase all flash contents  and collect the serial console output as suggested!
by (160 points)
I'm afraid the result was the same. Here's the link to the serial console output, I really appreciate you trying to help! https://www.dropbox.com/s/3kgaiiaqqt9o8wj/Serial_output.txt?dl=0
by (19.9k points)
I have a smoking gun but I've got no time currently to test/verify. In your output we see that it tries to get a token ('POST /api/token') yet on lines 27/28 we also see that the extracted tokens are empty. That is likely the same issue as here: https://github.com/ThingPulse/esp8266-weather-station/commit/038c4dacd838bf7819706b2b0cc0d5229b3ff475 Arduino changed some low-level networking behavior which required us to update our libraries.

Can you try to change all do-while socket parse loops e.g. https://github.com/ThingPulse/esp8266-spotify-remote/blob/master/SpotifyClient.cpp#L251-L264 so they follow the same pattern as shown in the commit above?

    while(client->connected() || client->available()) {
      while((size = client->available()) > 0) {
by (160 points)
I'm sorry to tell that I tried this to no avail. But I'm not an experienced C/C++ programmer, so please take that in consideration.

Cheers
by (19.9k points)
Thanks for trying! I might find some time over the weekend for testing. It's unfamiliar territory for me as well. I didn't write that code and it's been half a year since I lasted tested the whole flow.
by (160 points)
No problem! Even though I  bought the kit with the Spotify Remote in mind it's no big deal waiting a bit. I'll just use it as a weather station in the meantime :-)

Cheers
by (19.9k points)
I couldn't reproduce the problem here. The app worked just fine as-is. That doesn't necessarily mean much. It was the same with the issues that were reported against our weather station lib.

However, FWIW I still changed the TCP parse loops as described and pushed the changes to GitHub. It /still/ works ;-). So you might want to give the new version a try.

I doubt it helps much but here's my (redacted) console log: https://pastebin.com/n7qHacK7
by (160 points)
That's very interesting. If you can't reproduce the problem in your environment then maybe the problem lies in mine? Anyway, first I will try your updated SpotifyClient.cpp, and if the problem persists I'm going to do a clean Arduino installation on an old spare pc and see how that turns out. A shot in the dark, but might be worth while to try.Thank's a lot for your time and help, it's appreciated!

Cheers

3 Answers

0 votes
by (10.8k points)
Hi Thorleif

My first guess would be that your SPIFFS settings are wrong. The spotify client needs to store some credentials in the flash memory. Can you please check what you have set in Arduino IDE > Tools > Flash Size settings? If you have set the right board (Wemos D1 mini pro) then the only option is 16M (15MB SPIFFS). But if you have chosen the generic ESP8266 board instead the default is 512k (no SPIFFS) which would be wrong...

Cheers,
Dani
by (160 points)
Hi Dani,

Thanks for the quick reply. Seems like the settings is correct, though. The chosen board is listed as LOLIN(WEMOS) D1 mini Pro, and the only flash option is as you say 16M (15MB SPIFFS).

Cheers,
Thorleif
0 votes
by (160 points)

Update: I've just tried to replace the Wemos-board from the kit with another one, in case something could be wrong with the board itself, but the problem still persists sad

Greatful for any ideas of what to try, I'm stuck!

Cheers,

Thorleif

by (3.6k points)
Are you really sure the  Spotify unique Client ID and Client Secret elements are correct? The API error suggests there is an error with one of them, or both.
by (160 points)
Yes, it seems like those are correct. Just a copy and paste from my Espotifyer app page into
 settings.h. Did even create a new app just in case, but still the same. I've got Spotify Premium for Family, but I guess there's no reason to believe that there is some sort of restriction on this account type?
by (290 points)
I'm having the same issue. The first time I ran the sketch, it managed to authorize the API access but ended on the "Please define clientId and clientSecret screen"

It appears that some configuration values are stored in NVRAM as I've deleted my project and created an entirely new client id an secret and sent that several times to the ESP.

Have you had any success moving past this?
by (160 points)
Unfortunately not. I put the project on the shelf  for a while, will make a new try to get it working later this fall. If I succeed I'll post an update in this thread.
0 votes
by (290 points)

TL;DR: Wipe All Flash Contents to get a fresh start 

  • Open esp8266-spotify-remote.ino sketch in Arduino IDE
  • Choose Tools > Erase Flash: All Flash Contents
  • Upload sketch and follow prompts 

The ESP has some Flash Memory where the WiFi credentials and the Client ID/Secret are stored. If you made changes to the secret or client ID at the Spotify API console, you may need to update the credentials stored in the Flash Memory. The sketch assumes that if the files exist within the flash memory, they don't need to be updated. I haven't yet learned how to update the contents of the flash memory, but I did figure out that you can wipe the flash memory when you upload a new project.

Updating your credentials in settings.h and sending sketch again should help.

by (160 points)
Thanks for helping out, but I've already tried these steps several times to no avail.

Welcome to ThingPulse Q&A, where you can ask questions and receive answers from other members of the community.

https://thingpulse.com

...