#include #include #include #include #include #include #include #include #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); char ssid[] = ""; char password[] = ""; char clientId[] = ""; char clientSecret[] = ""; #define SPOTIFY_MARKET "US" #define SPOTIFY_REFRESH_TOKEN "" WiFiClientSecure client; SpotifyArduino spotify(client, clientId, clientSecret, SPOTIFY_REFRESH_TOKEN); unsigned long delayBetweenRequests = 10000; unsigned long requestDueTime; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.println(""); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); #if defined(ESP8266) client.setFingerprint(SPOTIFY_FINGERPRINT); #elif defined(ESP32) client.setCACert(spotify_server_cert); #endif Serial.println("Refreshing Access Tokens"); if (!spotify.refreshAccessToken()) { Serial.println("Failed to get access tokens"); } if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 allocation failed")); for(;;); } delay(2000); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); } void printCurrentlyPlayingToDisplay(CurrentlyPlaying currentlyPlaying) { display.clearDisplay(); display.setCursor(0, 10); display.println("Currently Playing:"); display.println(currentlyPlaying.trackName); display.println("by"); display.println(currentlyPlaying.artists[0].artistName); display.display(); } void loop() { if (millis() > requestDueTime) { Serial.print("Free Heap: "); Serial.println(ESP.getFreeHeap()); Serial.println("Getting currently playing song:"); int status = spotify.getCurrentlyPlaying(printCurrentlyPlayingToDisplay, SPOTIFY_MARKET); if (status == 200) { Serial.println("Successfully got currently playing"); } else if (status == 204) { Serial.println("Doesn't seem to be anything playing"); } else { Serial.print("Error: "); Serial.println(status); } requestDueTime = millis() + delayBetweenRequests; } }