-
Notifications
You must be signed in to change notification settings - Fork 461
Step by Step RPi3 Install of Sonos http api
Steps to install the sonos-http-api on a Raspberry Pi 3 (RPi 4 should work just the same)
BLANK SD CARD - Install Raspbian Buster
Download from https://www.raspberrypi.org/downloads/ Use an application such as Win32DiskImager and a card reader to burn onto SD Card (or Flash drive) Before removing the SD card from the Card Reader use File explorer to view the content of the SD Card Place a file called SSH (no file extension) into the root folder of the SD Card. This will allow you SSH into the Pi and use it headless
Place SD Card into Pi, connect Ethernet and apply power Use Advanced Port Scanner (PC) or Fing (mobile) to find the IP address of the PI Use Putty to SSH into the PI (enter IP address and port 22) Login into Pi
- Username - pi
- password - raspberry You can change the password if you like
INSTALL NODE.JS & NPM
I use Node.js v8 here as there appears to be a conflict netween v10 and npm where npm doesn't work correctly. Npm is included in the Node v8 release below
Clone/Copy to the Pi
Extract & Install using
- tar -xzf node-v8.17.0-linux-armv7l.tar.gz
- cd node-v8.17.0-linux-armv7l
- sudo cp -R * /usr/local/
Reboot Pi using
- sudo reboot
Use following commands to veryify install
- node -v
- npm -v
INSTALL SONOS HTTP API
Clone http api files to PI
- sudo git clone https://github.com/jishi/node-sonos-http-api.git
- ls (will display files folder)
- cd node-sonos-http-api (change to api folder)
- sudo npm install --production
- sudo npm start (this will start sonos-http-api service) You should see references to sonos rooms, etc
Now open a browser and assuming your sonos zone/room name is Kitchen you can confirm that the api is working by entering the following
- http://<rpi_ip_address>:5005/kitchen/state
For me my rpi address is http://192.168.1.240:5005/kitchen/state
You should see something like
{"volume":13,"mute":false,"equalizer":{"bass":7,"treble":9,"loudness":true},"currentTrack":{"artist":"Cork's 96fm","title":"x-sonosapi-stream:s15078?sid=254","albumArtUri":"/getaa?s=1&u=x-sonosapi-stream%3as15078%3fsid%3d254","duration":0,"uri":"x-sonosapi-stream:s15078?sid=254","trackUri":"x-sonosapi-stream:s15078?sid=254","type":"radio","stationName":"Cork's 96fm","absoluteAlbumArtUri":"http://192.168.1.63:1400/getaa?s=1&u=x-sonosapi-stream%3as15078%3fsid%3d254"},"nextTrack":{"artist":"","title":"","album":"","albumArtUri":"","duration":0,"uri":""},"trackNo":1,"elapsedTime":25197,"elapsedTimeFormatted":"06:59:57","playbackState":"PLAYING","playMode":{"repeat":"none","shuffle":false,"crossfade":false}}
START API ON PI POWERUP
Install pm2 by running the following commands
-
sudo reboot
-
npm install -g pm2
-
pm2 startup raspberry or
-
pm2 startup (if error encountered)
-
sudo env PATH=$PATH:/usr/local/bin pm2 startup raspberry -u pi
-
cd node-sonos-http-api
-
sudo pm2 start server.js -x --name "http-api" (you can change the name from http-api to anything you want, eg sonosapi)
-
pm2 save (save the pm2 config)
-
pm2 status (optional: show the current pm2 status to confirm the server started)
-
pm2 list (optional: list all currently running pm2 processes)
-
pm2 dump
Reboot Pi using
- sudo reboot
Confirm service starts automatically by using browser commands above
CONFIGURE TTS (TEXTTOSPEECH) FUNCTIONS OF THE SONOS API
If you want to use TTS, add a config
- cd node-sonos-http-api
- sudo nano settings.json
Amend as you need - I use AWS Polly and these are my settings
{ "aws": { "credentials": { "region": "eu-west-1", "accessKeyId": "XXXXXXXXXXXXXXXXXXXXX", "secretAccessKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, "name": "Emma" } }
Reboot Pi using
- sudo reboot
BOOT FROM FLASH DRIVE
If you have a Pi3 you can get your Pi to boot from a Flash Drive/Memory Stick by the following method For this you will need both an SD Card and a Flash Drive/Memory Stick, both with a Raspbian image burned on Add the SSH file in the root of both the SD Card and Flash Drive/Memory as described above to enable SSH access from each to the Pi
Boot up the PI with the SD card SSH in the Pi Enter the following commands (one per line)
- sudo apt-get update && sudo apt-get upgrade
- echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
- vcgencmd otp_dump | grep 17:
The last command should give a result like
- 17:3020000a If not then repeat the above steps
(taken from https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md)
Power off pi Remove the SD Card and insert the Flash Drive/Memory Stick into one USB port Add power and ethernet and let it boot
It can take up to 30 seconds to boot up SSH in as normal