Wednesday 21 March 2018

Set up Orange Pi One as part of a multi room audio system - using Mopidy & Snapcast

I usually use Raspberry Pi but as the Orange Pi One was so cheap I bought one about a year ago to try out. I couldn't get it to boot up and eventually gave up trying.
Last week somebody asked if I had ever used the Orange Pi with Mopidy and I thought it was about time I tried again.
Luckily this time I had a spare 8gb class 10 micro sd card - (I had previously tried with a 4gb class 4) and once I had downloaded the image and put it on the card I got results straight away. So only use a decent, fast card!!
Took some time to sort out the bits but basic run through is listed below, hope it helps somebody.

I used an Armbian image from https://armbian.com it seems to be a recommended source.and in here
There is plenty of choice, I tried a desktop system with Ubuntu and although I was impressed with the speed it went, I had problems with getting Mopidy to work, I put this down to Pulse Audio being preinstalled, but I now don't think it was Pulse causing the problems.

I used the Debian Stretch, this is command line only. But there are loads to choose from.
https://dl.armbian.com/orangepione/archive/ 
Armbian_5.38_Orangepione_Debian_stretch_next_4.14.14

So download and write image to card - put the card in machine and boot.

SSH in and you will be asked for name & password, name is root and password 1234.

You will need to change password, I went for musicbox.
Then you will create a new user, I called mine pi and password of raspberry.
Asks your name etc can just hit 'enter' all those, unless you want it personalised.
Instructions are on Armbian website on all this.

Whilst signed in as root I

apt update
apt upgrade

reboot

I then signed in as user pi and password raspberry - you could sign in as root and carry on.

I took ages to sort out Mopidy, it was playing but no sound, Snapclient and systems sounds were fine but not matter what I did I could not sort out Mopidy - eventually I came across  a link on Mopidy site and some of the files aren't installed in basic versions of Debian. Result is you need these files.

sudo apt install gstreamer1.0-alsa       Required for Mopidy
sudo apt-get update
sudo apt-get install avahi-daemon       Required for Snapcast (Client)
sudo reboot

Follow mopidy instructions for install and to run as a service (sudo dpkg-reconfigure mopidy)
Install Spotify

sudo apt-get install mopidy-spotify

You'll need pip for install later

sudo apt update
sudo apt install python-pip

You will need to fill in your /etc/mopidy/mopidy.conf file, I copy and pasted one from another Pi.
sudo nano /etc/mopidy/mopidy.conf file

Don't forget to visit github page to authenticate your Spotify account. Then enter the secrets into your /etc/mopidy/mopidy.conf file. 


You have plenty of choices for web extension, for simplicity I use musicbox web client so pip on and install.

sudo reboot

Try it and see if anything comes from speakers - if not;

Use alsamixer to check volume of card and get the card number, it was 1 in my case.

alsamixer

Make the file
sudo nano /etc/asound.conf

and enter the text
pcm.!default {
type hw
card 1 # your card number here
}
ctl.!default {
type hw
card 1 # your card number here.
}

Save and exit.

sudo reboot

Try again - hopefully there will be music!!

To set up for use as a multi room audio please read on - I assume you already have snapserver installed and running somewhere.

Below is only my way of making the multiroom system work - there are probably other ways but this works for us at home.
On clients where you intend playing music independently of snapserver/client, i.e. using the satellite as a standalone audio box as well as part of the multi room audio you need the webclient to have a stop button, as this means Mopidy will release the audio card, if it only has pause button Mopidy will keep hold of the audio card and snapclient will close when you try to use it.
Snapclient itself lets go of the card seconds after stream stops so it's not a problem going the other way.

Mopidy-moped has stop button but I prefer Iris. If the version of Iris doesn't behave try Mopidy moped
Unfortunately with many upgrades to Iris it's intermittent whether the stop button stops or pauses.
Current version is 3.14.2 however this doesn't stop, only pauses play
I am using 3.12.4 which does stop and clears playing track.
Up to you how you do it, but if you go for 3.12.4 remember not to upgrade.

Download, unzip and install the file

sudo wget https://github.com/jaedb/Iris/archive/3.12.4.tar.gz
tar -xvzf 3.12.4.tar.gz
sudo easy_install Iris-3.12.4

Open Iris and fill in your details on the settings page. 

sudo reboot

Play a tune using Iris and make sure that when you click the stop button, the music stops and the progress bar goes back to zero.

Download and install the latest version of Snapclient

sudo wget https://github.com/badaix/snapcast/releases/download/v0.13.0/snapclient_0.13.0_armhf.deb

sudo dpkg -i snapclient_0.13.0_armhf.deb

Install missing dependencies, there are a lot of them!!

sudo apt-get -f install

It won't install properly until you have got the dependencies

sudo reboot

You may need to reboot your snapserver machine - once back up you should see the Orange Pi appear in the list of clients. Start to play from snapserver machine, if you don't hear anything on the Orange Pi get a list of the audio card numbers and select yours from it.

sudo snapclient -l

sudo systemctl stop snapclient

Then run through the numbers until you find the right one

snapclient -s 1
snapclient -s 2

eventually as long as all is ok you will find the right number. If you are having problems shut down mopidy to make sure it's not holding onto the audio card.

Enter the correct card number in the

sudo nano/etc/default/snapclient 
snapclient_opts="-s 14"

Hopefully you'll be up and running now.