Overview
The Spotify MacroBoard requires a personal server that acts as a proxy between the ESP32 and the Spotify Web API. This server handles OAuth authentication, token refresh, and API requests on behalf of the MacroBoard.The reference implementation runs on
benzhou.tech at port 443 (HTTPS). You’ll need to set up your own server with a similar configuration.Why a proxy server?
The ESP32 has limited computational resources and memory, making it impractical to:- Implement OAuth 2.0 authentication flow
- Store and refresh access tokens
- Parse complex JSON responses from Spotify API
- Handle API rate limiting and retries
Server requirements
Domain and SSL certificate
Your server must be accessible via HTTPS with a valid SSL certificate:- Domain name: The ESP32 connects to a hardcoded domain (e.g.,
benzhou.tech) - SSL certificate: Required for secure HTTPS communication
- Port 443: Standard HTTPS port
Obtaining your SSL certificate
After setting up your server with an SSL certificate, extract the certificate:-----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----) into your SampleCredentials.h file:
Spotify API setup
Before implementing your server, register your application with Spotify:1. Create a Spotify app
- Go to Spotify Developer Dashboard
- Log in with your Spotify account
- Click “Create app”
- Fill in the app details:
- App name: Spotify MacroBoard Server
- App description: Personal proxy server for ESP32 MacroBoard
- Redirect URI:
https://your-domain.com/callback
- Accept the terms and click “Create”
2. Get your credentials
After creating the app:- Click on your app in the dashboard
- Go to “Settings”
- Note your Client ID and Client Secret
- These will be used in your server implementation
3. Required scopes
Your server needs to request the following OAuth scopes:user-read-playback-state- Get current playback informationuser-modify-playback-state- Control playback (play, pause, skip, etc.)user-read-currently-playing- Get currently playing track
Server implementation
Your server must implement two endpoints that match the ESP32’s expectations:Endpoint 1: Manage playback state
- Validate the password parameter
- Map the action to the appropriate Spotify API endpoint:
playPause→ PUT/me/player/pauseor/me/player/playskip→ POST/me/player/nextback→ POST/me/player/previousvinc→ PUT/me/player/volume(increase by 10%)vdec→ PUT/me/player/volume(decrease by 10%)shuffle→ PUT/me/player/shuffleloop→ PUT/me/player/repeat
- Make the authenticated request to Spotify API
- Return success/failure status
Endpoint 2: Get current playback
string
Current track title
string
Artist name (first artist if multiple)
string
Album name
integer
Track duration in seconds
integer
Current playback position in seconds
boolean
Whether playback is currently paused
integer
Current volume level (0-100)
array
RGB color array extracted from album artwork [R, G, B] where each value is 0-255
Album art color extraction
Thecolor field provides an RGB array that represents the dominant color from the album artwork. The ESP32 uses this to set the RGB LED strip color, creating ambient lighting that matches the current track.
Implementation approaches:
- Image processing library: Use a library like Pillow (Python) or Sharp (Node.js) to analyze the album art
- Color quantization: Extract the dominant color using k-means clustering or similar algorithms
- Caching: Cache colors by album ID to avoid reprocessing
Example server (Node.js)
Here’s a basic implementation using Node.js and Express:Token refresh
Spotify access tokens expire after 1 hour. Implement automatic token refresh:Testing your server
Before connecting the ESP32, test your endpoints:getCurrent:
Updating ESP32 configuration
After setting up your server, update yourSampleCredentials.h file:
src.ino:195 and src.ino:210:
Next steps
API endpoints
Detailed reference for all API endpoints
Troubleshooting
Common issues and solutions