66 lines
2.1 KiB
Arduino
66 lines
2.1 KiB
Arduino
#include <ESP8266WiFi.h>
|
|
#include <WiFiClientSecure.h>
|
|
#include <SpotifyArduino.h>
|
|
#include <ArduinoJson.h> // Wichtig für die Verarbeitung
|
|
|
|
// Deine Daten
|
|
char ssid[] = "Wayne Manor";
|
|
char password[] = "einfach10zeichen!";
|
|
char clientId[] = "510f19fec68e42f39aad137b7666433f"; // Von deinem Screenshot
|
|
char clientSecret[] = "f13ea80ae8d641a0a449e84cbac7efde"; // Klicke auf "View client secret" im Dashboard
|
|
char refreshToken[] = "AQB5Orf0ymkJabrduB8uxYgtrwoUrrY6Y5upjoiyyQm7pklhFSzWuqX-fdLUZprQjpZ17seJja0wuHYM0bGPCUas22jcla-evEqu6PhtJkLRealUn8L9w2D8TZlijxfON0I";
|
|
WiFiClientSecure client;
|
|
SpotifyArduino spotify(client, clientId, clientSecret, refreshToken);
|
|
|
|
unsigned long delayBetweenRequests = 5000; // 5 Sekunden
|
|
unsigned long lastTimeChecked;
|
|
|
|
// WICHTIG: Der Typ heißt "CurrentlyPlaying" und liegt im Namespace "SpotifyArduino"
|
|
void printSongDetails(CurrentlyPlaying currentlyPlaying) {
|
|
Serial.println("--------- NEUER SONG ---------");
|
|
Serial.print("Titel: ");
|
|
Serial.println(currentlyPlaying.trackName);
|
|
Serial.print("Interpret: ");
|
|
Serial.println(currentlyPlaying.artists[0].artistName);
|
|
Serial.print("Album: ");
|
|
Serial.println(currentlyPlaying.albumName);
|
|
Serial.println("------------------------------");
|
|
}
|
|
|
|
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.println("WiFi verbunden!");
|
|
|
|
// Erlaubt HTTPS ohne Fingerprint-Check
|
|
client.setInsecure();
|
|
}
|
|
|
|
void loop() {
|
|
if (millis() > lastTimeChecked + delayBetweenRequests) {
|
|
Serial.println("Frage Spotify ab...");
|
|
|
|
// Die Library nutzt intern den Typ "CurrentlyPlaying"
|
|
int status = spotify.getCurrentlyPlaying(printSongDetails, "DE");
|
|
|
|
if (status == 200) {
|
|
// Alles okay, Song wird in printSongDetails ausgegeben
|
|
} else if (status == 204) {
|
|
Serial.println("Nichts wird abgespielt (oder Spotify ist im Private Session Mode).");
|
|
} else {
|
|
Serial.print("Fehler beim Abruf. Status Code: ");
|
|
Serial.println(status);
|
|
}
|
|
|
|
lastTimeChecked = millis();
|
|
}
|
|
} |