#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
const char* ssid = "";
const char* password = "";
const char* host = "api.spotify.com";
const int httpsPort = 443;
const char* accessToken = "";
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client;
client.setInsecure();
if (client.connect(host, httpsPort)) {
String endpoint = "/v1/me/player/recently-played?limit=1";
String header = "GET " + endpoint + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Authorization: Bearer " + accessToken + "\r\n" +
"Connection: close\r\n\r\n";
client.print(header);
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
break;
}
}
String response = client.readString();
Serial.println(response);
} else {
Serial.println("Connection failed");
}
}
delay(60000); // 1 dakika bekleme
}
}