Skip to content

Commit 7d44970

Browse files
committed
Updating all examples (untested)
1 parent b85e426 commit 7d44970

File tree

4 files changed

+219
-124
lines changed

4 files changed

+219
-124
lines changed

examples/getCurrentlyPlaying/getCurrentlyPlaying.ino

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
* * = Affiliate
1515
16-
If you find what I do usefuland would like to support me,
16+
If you find what I do useful and would like to support me,
1717
please consider becoming a sponsor on Github
1818
https://github.com/sponsors/witnessmenow/
1919
@@ -150,10 +150,6 @@ void printCurrentlyPlayingToSerial(CurrentlyPlaying currentlyPlaying)
150150
Serial.println(currentlyPlaying.artists[i].artistUri);
151151
Serial.println();
152152
}
153-
Serial.println(currentlyPlaying.firstArtistName);
154-
Serial.print("Artist URI: ");
155-
Serial.println(currentlyPlaying.firstArtistUri);
156-
Serial.println();
157153

158154
Serial.print("Album: ");
159155
Serial.println(currentlyPlaying.albumName);

examples/playAdvanced/playAdvanced.ino

+72-37
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
NOTE: You need to get a Refresh token to use this example
1212
Use the getRefreshToken example to get it.
1313
14+
Compatible Boards:
15+
- Any ESP8266 or ESP32 board
16+
1417
Parts:
15-
ESP32 D1 Mini stlye Dev board* - http://s.click.aliexpress.com/e/C6ds4my
18+
ESP32 D1 Mini style Dev board* - http://s.click.aliexpress.com/e/C6ds4my
1619
17-
* * = Affilate
20+
* * = Affiliate
1821
19-
If you find what I do usefuland would like to support me,
22+
If you find what I do useful and would like to support me,
2023
please consider becoming a sponsor on Github
2124
https://github.com/sponsors/witnessmenow/
2225
@@ -27,23 +30,31 @@
2730
Twitter: https://twitter.com/witnessmenow
2831
*******************************************************************/
2932

30-
3133
// ----------------------------
3234
// Standard Libraries
3335
// ----------------------------
3436

37+
#if defined(ESP8266)
38+
#include <ESP8266WiFi.h>
39+
#elif defined(ESP32)
3540
#include <WiFi.h>
41+
#endif
42+
3643
#include <WiFiClientSecure.h>
3744

3845
// ----------------------------
3946
// Additional Libraries - each one of these will need to be installed.
4047
// ----------------------------
4148

42-
#include <ArduinoSpotify.h>
49+
#include <SpotifyArduino.h>
4350
// Library for connecting to the Spotify API
4451

4552
// Install from Github
46-
// https://github.com/witnessmenow/arduino-spotify-api
53+
// https://github.com/witnessmenow/spotify-api-arduino
54+
55+
// including a "spotify_server_cert" variable
56+
// header is included as part of the SpotifyArduino libary
57+
#include <SpotifyArduinoCert.h>
4758

4859
#include <ArduinoJson.h>
4960
// Library used for parsing Json from the API responses
@@ -56,122 +67,140 @@
5667
char ssid[] = "SSID"; // your network SSID (name)
5768
char password[] = "password"; // your network password
5869

59-
char clientId[] = "56t4373258u3405u43u543"; // Your client ID of your spotify APP
70+
char clientId[] = "56t4373258u3405u43u543"; // Your client ID of your spotify APP
6071
char clientSecret[] = "56t4373258u3405u43u543"; // Your client Secret of your spotify APP (Do Not share this!)
6172

73+
// Country code, including this is advisable
74+
#define SPOTIFY_MARKET "IE"
75+
6276
#define SPOTIFY_REFRESH_TOKEN "AAAAAAAAAABBBBBBBBBBBCCCCCCCCCCCDDDDDDDDDDD"
6377

6478
//------- ---------------------- ------
6579

66-
// including a "spotify_server_cert" variable
67-
// header is included as part of the ArduinoSpotify libary
68-
#include <ArduinoSpotifyCert.h>
69-
7080
WiFiClientSecure client;
71-
ArduinoSpotify spotify(client, clientId, clientSecret, SPOTIFY_REFRESH_TOKEN);
81+
SpotifyArduino spotify(client, clientId, clientSecret, SPOTIFY_REFRESH_TOKEN);
7282

73-
void playSingleTrack(){
83+
void playSingleTrack()
84+
{
7485
char sampleTrack[] = "spotify:track:4uLU6hMCjMI75M1A2tKUQC";
7586
char body[100];
7687
sprintf(body, "{\"uris\" : [\"%s\"]}", sampleTrack);
77-
if (spotify.playAdvanced(body)) {
88+
if (spotify.playAdvanced(body))
89+
{
7890
Serial.println("sent!");
7991
}
8092
}
8193

82-
void playMultipleTracks(){
94+
void playMultipleTracks()
95+
{
8396
char sampleTrack1[] = "spotify:track:6vW1WpedCmV4gtOijSoQV3";
8497
char sampleTrack2[] = "spotify:track:4dJYjR2lM6SmYfLw2mnHvb";
8598
char sampleTrack3[] = "spotify:track:4uLU6hMCjMI75M1A2tKUQC";
8699

87100
char body[200];
88101
sprintf(body, "{\"uris\" : [\"%s\", \"%s\", \"%s\"]}", sampleTrack1, sampleTrack2, sampleTrack3);
89-
if (spotify.playAdvanced(body)) {
102+
if (spotify.playAdvanced(body))
103+
{
90104
Serial.println("sent!");
91105
}
92106
}
93107

94-
void playAlbum(){
108+
void playAlbum()
109+
{
95110
char sampleAlbum[] = "spotify:album:6N9PS4QXF1D0OWPk0Sxtb4";
96111

97112
char body[100];
98113
sprintf(body, "{\"context_uri\" : \"%s\"}", sampleAlbum);
99-
if (spotify.playAdvanced(body)) {
114+
if (spotify.playAdvanced(body))
115+
{
100116
Serial.println("sent!");
101117
}
102118
}
103119

104-
void specifyTrackNumOfAlbum(){
120+
void specifyTrackNumOfAlbum()
121+
{
105122
char sampleAlbum[] = "spotify:album:2fPcSpVFVo1dXEvarNoFkB";
106123
// The position has an index of 0, so passing in 2
107124
// like this will actually play the 3rd song.
108125
int trackNum = 2;
109126

110127
char body[200];
111128
sprintf(body, "{\"context_uri\" : \"%s\", \"offset\": {\"position\": %d}}", sampleAlbum, trackNum);
112-
if (spotify.playAdvanced(body)) {
129+
if (spotify.playAdvanced(body))
130+
{
113131
Serial.println("sent!");
114132
}
115133
}
116134

117-
void specifyTrackOfAlbum(){
135+
void specifyTrackOfAlbum()
136+
{
118137
char sampleAlbum[] = "spotify:album:2BLjT6yzDdKojUyc3Gi6y2";
119138
char trackOnAlbum[] = "spotify:track:25IZtuJS77yXPCXMhPa1ze";
120139

121140
char body[200];
122141
sprintf(body, "{\"context_uri\" : \"%s\", \"offset\": {\"uri\": \"%s\"}}", sampleAlbum, trackOnAlbum);
123-
if (spotify.playAdvanced(body)) {
142+
if (spotify.playAdvanced(body))
143+
{
124144
Serial.println("sent!");
125145
}
126146
}
127147

128-
void playArtist(){
148+
void playArtist()
149+
{
129150
char sampleArtist[] = "spotify:artist:0gxyHStUsqpMadRV0Di1Qt";
130151

131152
char body[100];
132153
sprintf(body, "{\"context_uri\" : \"%s\"}", sampleArtist);
133-
if (spotify.playAdvanced(body)) {
154+
if (spotify.playAdvanced(body))
155+
{
134156
Serial.println("sent!");
135157
}
136158
}
137159

138-
void playPlaylist(){
160+
void playPlaylist()
161+
{
139162
char samplePlaylist[] = "spotify:playlist:37i9dQZF1DZ06evO05tE88";
140163

141164
char body[100];
142165
sprintf(body, "{\"context_uri\" : \"%s\"}", samplePlaylist);
143-
if (spotify.playAdvanced(body)) {
166+
if (spotify.playAdvanced(body))
167+
{
144168
Serial.println("sent!");
145169
}
146170
}
147171

148-
void specifyTrackNumOfPlaylist(){
172+
void specifyTrackNumOfPlaylist()
173+
{
149174
char samplePlaylist[] = "spotify:playlist:37i9dQZF1DZ06evO05tE88";
150175
// The position has an index of 0, so passing in 31
151176
// like this will actually play the 32nd song.
152177
int playlistTrackNum = 31;
153178

154179
char body[200];
155180
sprintf(body, "{\"context_uri\" : \"%s\", \"offset\": {\"position\": %d}}", samplePlaylist, playlistTrackNum);
156-
if (spotify.playAdvanced(body)) {
181+
if (spotify.playAdvanced(body))
182+
{
157183
Serial.println("sent!");
158184
}
159185
}
160186

161-
void specifyTrackOfPlaylist(){
187+
void specifyTrackOfPlaylist()
188+
{
162189
char samplePlaylist[] = "spotify:playlist:37i9dQZF1DZ06evO05tE88";
163190
char trackOnPlaylist[] = "spotify:track:6vW1WpedCmV4gtOijSoQV3";
164191

165192
char body[200];
166193
sprintf(body, "{\"context_uri\" : \"%s\", \"offset\": {\"uri\": \"%s\"}}", samplePlaylist, trackOnPlaylist);
167-
if (spotify.playAdvanced(body)) {
194+
if (spotify.playAdvanced(body))
195+
{
168196
Serial.println("sent!");
169197
}
170198
}
171199

172-
void setup() {
200+
void setup()
201+
{
173202

174-
Serial.begin(115200);
203+
Serial.begin(115200);
175204

176205
// Set WiFi to station mode and disconnect from an AP if it was Previously
177206
// connected
@@ -194,13 +223,21 @@ void setup() {
194223
IPAddress ip = WiFi.localIP();
195224
Serial.println(ip);
196225

226+
// Handle HTTPS Verification
227+
#if defined(ESP8266)
228+
client.setFingerprint(SPOTIFY_FINGERPRINT); // These expire every few months
229+
#elif defined(ESP32)
197230
client.setCACert(spotify_server_cert);
231+
#endif
232+
// ... or don't!
233+
//client.setInsecure();
198234

199235
// If you want to enable some extra debugging
200236
// uncomment the "#define SPOTIFY_DEBUG" in ArduinoSpotify.h
201237

202238
Serial.println("Refreshing Access Tokens");
203-
if(!spotify.refreshAccessToken()){
239+
if (!spotify.refreshAccessToken())
240+
{
204241
Serial.println("Failed to get access tokens");
205242
return;
206243
}
@@ -232,11 +269,9 @@ void setup() {
232269
delay(10000);
233270
Serial.println("Playing specific track on Playlist");
234271
specifyTrackOfPlaylist();
235-
236272
}
237273

238-
239274
// Example code is at end of setup
240-
void loop() {
241-
275+
void loop()
276+
{
242277
}

0 commit comments

Comments
 (0)