Record player built with NodeMCU, ESP8266, PN532, and the Spotify Web API.
- Make sure the PN532 module is in SPI mode, this can be configured through the switches on the board
- Download the ESP8266 module libraries following the instructions in the esp8266/Arduino repository
- Download the PN532 module libraries following the elechouse/PN532 getting started guide
- In the Arduino board configuration, select the NodeMCU 1.0 (ESP-12E Module) board
- Select the correct serial port where the microcontroller is connected to
- Create a Spotify application following the steps in the Spotify developer documentation
- Set the application's Redirect URI setting to
http://<YOUR_BOARD_IP_ADDRESS>/oauth/spotify
- This can be set after loading the program into the microcontroller and which connects it to the WiFi network and its IP address can be determined
- Take note of the application's Client ID and Client Secret values
Copy secrets.example.txt
into secrets.cpp
, and set the values for these variables:
OAUTH_CLIENT_ID
andOAUTH_CLIENT_SECRET
- The Client ID and Client Secret values of the Spotify application
OAUTH_REDIRECT_URL
- Set to
http://<YOUR_BOARD_IP_ADDRESS>/oauth/spotify
and should match the Redirect URI value of the Spotify application
- Set to
WIFI_SSID
andWIFI_PASSWORD
- The WiFi network's name and password
NFC_AUTHENTICATION_KEY
(Optional)- If you are using custom authentication keys for the NFC cards, set them here, otherwise these are set to a default value
CA_CERTIFICATE
- These is the root CA certificate to verify the OAuth endpoints' SSL certificate
- To obtain these values for the Spotify APIs, run this command and copy the certificate in the output into this variable
openssl s_client -connect accounts.spotify.com:443 -showcerts
// secrets.cpp String CA_CERTIFICATE = R"CERT( -----BEGIN CERTIFICATE----- <CERTIFICATE_BODY_HERE> -----END CERTIFICATE----- )CERT";
- Connect the NodeMCU microcontroller to your computer
- Compile the code in
iot-record-player.ino
and upload it to the microcontroller
- Once the code has been uploaded and running in the microcontroller, visit
http://<YOUR_BOARD_IP_ADDRESS>
on your browser - This performs an OAuth flow with the Spotify application to get access tokens that can be used to send requests to the Spotify API
- After completing the OAuth flow, it's now ready to scan NFC cards and play its corresponding album/playlist on Spotify
- This project supports only Mifare Classic 1K NFC cards (4 bytes UID)
- The NFC cards need to store the Spotify context URI of the album or playlist
- Example:
spotify:album:1A3nVEWRJ8yvlPzawHI1pQ
- Example:
- The NFC cards should store data starting at block number 4 in its storage memory, this project will start reading data from block number 4 until it encounters a
0xff
byte- The
writeNfcData
function innfc.cpp
can be used to write data to the correct location in the NFC cards
- The