Spotify Connect on your RoonBridged Pi - the quick 'n easy way

UPDATE 08/20/2017: community member @Tony_Reimann kindly pointed to the existence of RaSpotify, a fully packaged librespot distribution that was released sometime after this thread was started. While the info below is technically still valid, RaSpotify is the better and easier solution.

Links and continued discussion here:

Spotify Connect on your RoonBridged Pi - the even quicker & easier way

=====

Sometimes I like Spotify – mostly for the playlists and the way it seems to know me well enough to cater to my tastes in recommendations. For those running a Pi (or similar SBC) with a HAT, there’s an easy way to add Spotify Connect without compiling and/or getting keys.

Ten easy steps:

  1. Install DietPi and RoonBridge in the usual way

  2. Look up the most recent release of Librespot and copy the link to the latest ZIP-file

  3. SSH into your Pi and get the ZIP (example; copy your own link after ‘wget’):

wget https://github.com/herrernst/librespot/releases/download/v20161230-7fd8503/librespot-linux-armhf-raspberry_pi.zip

  1. Unzip:

unzip librespot-linux-armhf-raspberry_pi.zip -d .

  1. Create the service definition:

nano /etc/systemd/system/spotify-connect.service

  1. Paste the following into the empty file:

[Unit]
Description=Spotify Connect
After=network-online.target
[Service]
Type=idle
User=root
ExecStart=/root/librespot --name SpotifyConnect --cache /tmp --bitrate 320 --backend alsa --device hw:0 > /dev/null 2>&1
Restart=always
RestartSec=10
StartLimitInterval=30
StartLimitBurst=20
[Install]
WantedBy=multi-user.target

  1. Save with CTRL-X, Y

  2. Reload daemons:

systemctl daemon-reload

  1. Enable your new service:

systemctl enable spotify-connect.service

  1. Enable and activate your new service:

systemctl start spotify-connect.service

That’s all. Spotify Connect will be loaded automatically every time you boot your Pi. It will automatically release ALSA a few seconds after playing is stopped, so RoonBridge can take over (alternately, RoonBridge releases ALSA a few seconds after playing is stopped as well).

Happy listening!

(This little guide was created from an excellent post by Ari at the Hifiberry forums).

13 Likes

It didn’t work for me. I got the following when querying the status

root@DietPi:~# systemctl status spotify-connect.service
● spotify-connect.service - Spotify Connect
   Loaded: loaded (/etc/systemd/system/spotify-connect.service; enabled)
   Active: active (running) since Fri 2017-01-06 13:09:25 NZDT; 10min ago
 Main PID: 454 (librespot)
   CGroup: /system.slice/spotify-connect.service
           └─454 /root/librespot --name SpotifyConnect --cache /tmp --bitrate 320 --backend alsa --device hw:0 > /dev/null 2>&1

Jan 06 13:14:01 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::107b:6fc5:5605:88d3]:5353): class 32769 is invalid
Jan 06 13:14:01 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::107b:6fc5:5605:88d3]:5353): class 32769 is invalid
Jan 06 13:14:02 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::107b:6fc5:5605:88d3]:5353): class 32769 is invalid
Jan 06 13:14:03 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::107b:6fc5:5605:88d3]:5353): class 32769 is invalid
Jan 06 13:14:03 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::107b:6fc5:5605:88d3]:5353): class 32769 is invalid
Jan 06 13:14:05 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::c25:1f57:8260:6d0c]:5353): class 32769 is invalid
Jan 06 13:14:05 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::107b:6fc5:5605:88d3]:5353): class 32769 is invalid
Jan 06 13:15:42 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::c25:1f57:8260:6d0c]:5353): class 32769 is invalid
Jan 06 13:17:21 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::c25:1f57:8260:6d0c]:5353): class 32769 is invalid
Jan 06 13:18:58 DietPi librespot[454]: WARN:mdns::fsm: couldn't parse packet from V6([fe80::c25:1f57:8260:6d0c]:5353): class 32769 is invalid
1 Like

Gonna try this tonight Rene, thanks very much :grinning:

What soundcard / DAC are you using? If it is not at hw:0, you have to change the card# in the service file. You can find out by issuing ‘aplay -l’.

This is the main command:

/root/librespot --name SpotifyConnect --cache /tmp --bitrate 320 --backend alsa --device hw:0

You can stop the service temporarily and try device settings by running the above command direct from the prompt until it runs OK – then change the service file accordingly and restart.

Maybe @Dan_Knight could implement this into the dietpi build (not that you have’nt got enough to do Dan :grinning:)

I know lots of Roon users have Spotify subscriptions.

1 Like

Thanks for this @RBM. Your instructions worked perfectly. Cheers

1 Like

I am using a Allo Piano Dac 2.1. The output of aplay -l is

**** List of PLAYBACK Hardware Devices ****
card 0: PianoDAC [PianoDAC], device 0: Piano DAC HiFi pcm512x-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0

so looks OK to me. I don’t see any Spotify Connect device at all. Running the command manually gives

root@DietPi:~# /root/librespot --name SpotifyConnect --cache /tmp --bitrate 320 --backend alsa --device hw:0
INFO:librespot::main_helper: librespot 3331338 (2016-12-30). Built on 2016-12-30.
INFO:librespot::main_helper: No username provided and no stored credentials, starting discovery …
WARN:mdns: Error creating IPv4 UDP socket for mDNS: No such device (os error 19)
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::c25:1f57:8260:6d0c]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::1817:83af:9f46:c362]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::1817:83af:9f46:c362]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::1817:83af:9f46:c362]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::1817:83af:9f46:c362]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::4c7:5fc5:c871:fed0]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::4c7:5fc5:c871:fed0]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::4c7:5fc5:c871:fed0]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::4c7:5fc5:c871:fed0]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::4c7:5fc5:c871:fed0]:5353): class 32769 is invalid
WARN:mdns::fsm: couldn’t parse packet from V6([fe80::4c7:5fc5:c871:fed0]:5353): class 32769 is invalid

@Tony_Reimann that seems to be rather network issue than DAC issue. Possibly some sort of ipv6 or mdns incompatibility - possibly upgrade of OS could help?

@RBM @Dan_Knight

Once again Rene, and for the first time Dan, thanks very much for all you do to allow this fuddy 50 year old to set up something like this!

Diet-Pi is amazing and I’m just heading over to add a few spondulicks to the budget.I know I only cut and pasted to get Spotify connect but it feels like magic to me!

Unfortunately this may mean quite a few silly questions may be asked here going forward!

SJB

SJB

2 Likes

Does your Pi have any internet connectivity at all? Can you ping external websites? (Try ‘ping google.com’).

It sure does have internet connectivity (needed it to get the s/w in the first place :slight_smile: ) Running the latest dietpi 1.41. Here is the ping of google just to prove internet connectivity

root@DietPi:~# ping www.google.com
PING www.google.com (216.58.199.36) 56(84) bytes of data.
64 bytes from www.google.com (216.58.199.36): icmp_seq=1 ttl=54 time=30.9 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=2 ttl=54 time=30.6 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=3 ttl=54 time=30.6 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=4 ttl=54 time=30.7 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=5 ttl=54 time=32.2 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=6 ttl=54 time=30.5 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=7 ttl=54 time=30.5 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=8 ttl=54 time=30.6 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=9 ttl=54 time=30.5 ms
64 bytes from www.google.com (216.58.199.36): icmp_seq=10 ttl=54 time=30.6 ms
^C
www.google.com ping statistics —
10 packets transmitted, 10 received, 0% packet loss, time 9015ms
rtt min/avg/max/mdev = 30.572/30.838/32.218/0.509 ms

I am stumped and want spotify connect so I really appreciate any help.

Could it be an issue with me using a Kali reclocker with the piano 2.1 dac?

OK I disabled IP V6 and bingo, all is good!

1 Like

:+1: Good to hear.

I ended up in a similar situation this morning after updating RoonBridge – so I guess the coexistence between the two is not yet as peaceful as we’d like.

Things stabilised after stopping the spotify-connect.service, restarting roonbridge.service and starting spotify-connect again. Lets see how this works out over time.

In the mean time I’ll add a spare Pi + Digi+ board running Librespot exclusively to the mix, as I found it to be more reliable and better sounding compared to the Chromecast Audio that was assigned to Spotify duty until now.

Is there a way to name the Spotify connect option, as I want to have it on 2 different Pis and need to be able to differentiate?

Thanks

SJB

Yes: repeat steps 5-10 (without the pasting part) and edit ‘–name SpotifyConnect’ to a name of your liking in step 5.

1 Like

cool, thanks Rene!
Now just to figure out a way to control the volume on the Dion Audio Loco DAC/Amp on the Pi… alsa doesn’t show anything that I can do and this thing can be loud…

Thanks @RBM!

My rpi now nicely becomes a sound hub, switching seamlessly between:

  • NAA for HQPlayer endpoint
  • Roon Bridge (in preparation for 1.3)
  • Shairport for that youtube sound
  • SpotifyConnect for that guilty pleasure
2 Likes

If I have spotify connect up and working do I have to do the extra step at 9 and if so where do I start.

(sorry if this is a silly question)

SJB

No silly questions here…

You won’t really need those services (I have since removed them from the first post) – this was me trying to make starting the service more reliable, but it looks like the embedded mDNS code is the culprit.

For now – if it works, it works. :wink:

Hi,

thanks for the great writeup/help, however I have one issue within my setup, although the Spotify App on my Android phone sees the Spotify Connect option, however when I choose it and press play I get no sound via the Sparky/Piano/Kali setup.

Roon bridge is working fine and sounds great however Spotify connect is running but with no output ( Spotify connect volume is max )

Internet connection is all good as I can listen to the radio stations via net connection

Any ideas?

Thanks,

Mike.