Open HudsonReid opened 1 day ago
LiquidCrystal_I2C lcd(0x27,16,2);
const int redbuttonPin = 14; // RED Button pin const int yellowbuttonPin = 35; // YELLOW Button pin const int greenbuttonPin = 34; // GREEN Button pin int redButtonState = 0; int yellowButtonState = 0; int greenButtonState = 0; bool isPlaying = true;
const char SSID = ""; const char PASSWORD = ""; const char CLIENT_ID = ""; const char CLIENT_SECRET = ""; const char* refresh_token = "";
//Create an instance of the Spotify class Optional: you can set the Port for the webserver the debug mode(This prints out data to the serial monitor) and number of retries Spotify sp(CLIENT_ID, CLIENT_SECRET, refresh__token);
void setup() { Serial.begin(115200); connect_to_wifi();//Connect to your wifi
user_tokens tokens = sp.get_user_tokens();
sp.begin();//Start the webserver
while(!sp.is_auth()){//Wait for the user to authenticate
sp.handle_client();//Handle the client, this is necessary otherwise the webserver won't work
}
Serial.println("Authenticated");
pinMode(redbuttonPin, INPUT);
pinMode(yellowbuttonPin, INPUT);
pinMode(greenbuttonPin, INPUT);
Wire.begin(SDA, SCL);
lcd.init();// initialize the lcd
lcd.backlight(); // Turns on the LCD backlight.
lcd.print("Hello, Welcome"); // Print a message to the LCD.
lcd.setCursor(0, 1);
lcd.print("To ESPotify32!");
delay(3000);
lcd.clear();
}
void loop() { static String lastArtist; static String lastTrackname;
// read the state of the button value
yellowButtonState = digitalRead(yellowbuttonPin);
Serial.println(isPlaying);
// check for pause
if (yellowButtonState == HIGH) {
if (isPlaying) {
isPlaying = false;
sp.pause_playback();
return;
} else {
isPlaying = true;
sp.start_resume_playback();
return;
}
}
// check for start over
redButtonState = digitalRead(redbuttonPin);
if (redButtonState == HIGH) {
sp.seek_to_position(0);
return;
}
// check for skip
greenButtonState = digitalRead(greenbuttonPin);
if (greenButtonState == HIGH) {
sp.skip();
return;
}
String currentArtist = sp.current_artist_names();
String currentTrackname = sp.current_track_name();
//isPlaying = sp.is_playing();
response r = sp.currently_playing();
print_response(r);
if (lastArtist != currentArtist && currentArtist != "Something went wrong" && !currentArtist.isEmpty()) {
lastArtist = currentArtist;
Serial.println("Artist: " + lastArtist);
lcd.clear();
lcd.setCursor(0, 1); // Sets the cursor position to the first row and first column (0, 0).
lcd.print("By: ");
lcd.print(lastArtist);
}
if (lastTrackname != currentTrackname && currentTrackname != "Something went wrong" && currentTrackname != "null") {
lastTrackname = currentTrackname;
Serial.println("Track: " + lastTrackname);
lcd.setCursor(0, 0);
lcd.print(lastTrackname);
}
} void connect_to_wifi(){ WiFi.begin(SSID, PASSWORD); Serial.print("Connecting to WiFi..."); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.printf("\nConnected to WiFi\n"); }
I will definitly take a look at this, i havent updated the library for a long time and the spotify API is updated quite frequently with a lot of changes eg in format etc. so that might be it.
void loop() { String currentArtist = sp.current_artist_names(); String currentTrackname = sp.current_track_name(); Serial.println(currentArtist); Serial.println(currentTrackname); }
I tried to reproduce your error with this, but it switches with new songs if you have any idea why you get your error feel free to contact me also over discord if you prefer could make a call there aswell if needed. If you are able to you might also try to print the data in the current_artist names function or the current track function
When I am using this library, setup and everything seems to go smooth, and the first song correctly gives me the artist and song name. However every subsequent song name after is returned null or something went wrong but the artist return value is perfect every time. I figured my token was expired or my calls were bad. However when I debug and add in the print_response(r) for r = sp.currently_playing(). I can see in my serial monitor that all the correct information is coming through. The weirdest part, is that if I switch platforms (ex. from phone to browser, browser to windows app) It immediately picks up and outputs the correct info, then every song after is messed up again. Any thoughts?