Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

pianod+wsgw: Pandora client/server with nice web interface:

Sun Mar 17, 2013 10:29 pm

pianod is a nice Pandora client/server that works great on RasPi (tested on Raspbian & Arch). It overlaps in functionality with pianobar, but is designed to run more as a background service instead of as an interactive program. It has a lot of nice features and is 100% open source. The author is actively developing it on Mac OS and I'm regularly testing it on RasPi and x86 Linux.

Once you have the pianod server running and connected to Pandora, you can control it over the network through a netcat/telnet connection, or using the included simple command-line client.

Recently the author has added a new tool, the WebSockets Gateway (wsgw). This is a really cool little program that I will post about more separately. Basically it forms a bridge between an HTML5 compliant browser (Chrome, Firefox, or Safari should all work, including Android/iOS versions) and any server with a network socket interface. This means that you can use a web client that is hosted on the pianod website to control your local RasPi instance of pianod, and you can do it from any HTML5 compliant device including your tablet or smartphone. Here's a screenshot of my setup:
Image

(If you want to tweak the web client you can download the source and host your version locally too.)

To get started, download the latest tarball and then head over to the wiki or the build instructions page. I can confirm that all the dependencies are available from the Raspbian and ArchLinuxARM repositories. (You can also pull the source anonymously from SVN, but to build from that you'll need autoconf.)

Building wsgw is a similar process, starting with the latest tarball.

If you have any questions, I'll be watching the pianod mailing list and this thread.

denverlittle
Posts: 4
Joined: Fri Mar 22, 2013 8:00 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Fri Mar 22, 2013 8:27 pm

This looks like a much better set up then what I am using now. Pianobar with a custom web ui. I am having some issue's getting it installed, failing to find required library libgcrypt. I went through the packages and tried installed what I thought was correct, but still receiving the same issue. Any help is greatly appreciated!

denverlittle
Posts: 4
Joined: Fri Mar 22, 2013 8:00 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Fri Mar 22, 2013 8:37 pm

I tried to install this but I'm getting a failure finding the required library libgcrypt. I installed what I thought was the proper package for Wheezy but same issue. Any assistance is greatly appreciated :)

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Fri Mar 22, 2013 10:10 pm

I'm not at my Pi at the moment, but one general note is that you need the devel versions of the dependencies. Hope that helps. Once I'm home I can give you specific help.


Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Wed May 01, 2013 2:03 pm

I spent a few hours setting this up last night.

Manually running pianod and wsgw as user "pi" with config files in ~/.config/pianod seems to work.

However I can't seem to get the provided init.d scripts to work. With those scripts installed and rc?.d symlinks created per your instructions ... now when I boot the system, it seems pianod launches but does not begin playing the station I've defined in startscript. The wsgw process doesn't launch at all.

If I manually restart the pianod service:

sudo /etc/init.d/pianod stop
sudo /etc/init.d/pianod start

Then the station begins playing. And if I then

sudo /etc/init.d/wsgw start

The web socket gateway starts too.

It seems like a timing thing, services starting before their requirements are ready, or something like that.

Suggestions?

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Wed May 01, 2013 7:55 pm

Hmmm, I've had issues like that with systemd on arch, but on raspbian the init scripts seemed to just work. I'll look into it, may take me a days.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Wed May 01, 2013 8:09 pm

Okay thanks.

Yes, this is rasbian and not arch. I'm going to be away from this particular raspberry pi for a week or so. It's not urgent, obviously, but would be nice to eventually get this working for coworkers back in the office.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sat May 04, 2013 5:33 am

That's great you are using it for an office environment. Perette, the developer of pianod has that use case in mind and has some interesting features (or planned features) for setting the QuickMix according to who is logged in. I am only using it at home right now, so I haven't played with these features myself.

The problem I'm having with systemd and wsgw on Arch is due to wsgw exiting if networking isn't available. Probably similar issues are hanging up your setup. I'm surprised this was never an issue on my Raspbian now that I think about it; what is your network setup (ethernet/wifi, etc.)?

I'm planning to patch wsgw so that it will defer host and service resolution if networking isn't available on startup; hopefully this coming week. But there should be other options. Try adding $network to the Required-Start/Required-Stop lines in the scripts, and then rerun update-rc.d pianod defaults. If that doesn't fix it, try adding $named. Let me know if that helps.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sat May 04, 2013 6:02 am

It's wifi using a supported adapter, can't remember the exact model. I can switch to ethernet as a test. I'll also try the Required-Start as you suggest and see about getting wsgw to launch reliably on boot.

I'm also struggling to figure out why I'm not getting audio from pianod unless I stop and restart the service. Maybe there we have the same issue with timing? I'm using a C-Media based USB audio adapter -- I wonder if pianod is launching before the USB adapter is initialized? I should plug in headphones in the pi's 3.5mm stereo jack.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sat May 04, 2013 6:21 am

I was imagining the problem was just that pianod was trying to startup your station before networking was available. But you're saying that if pianod starts on boot you can't get it to play anything even after everything is booted up?

Do you have MPD running with this setup? Maybe check the /etc/init.d/mpd script; it has Should-Start (a soft version of Required-Start) alsa-utils pulseaudio; you could try adding that.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sat May 04, 2013 6:26 am

I suppose that's possible? I would have thought pianod would pause and wait for networking to start. Eg what happens if networking is interrupted during playback?

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sat May 04, 2013 4:11 pm

Good point. Unfortunately pianod doesn't handle these situations equivalently.

If you lose connection while playing, it will enter Stalled state (once it runs out of cache) and then it should recover when the connection returns.

If you don't have a connection when you are starting up though, then pianod isn't able to log onto Pandora and get your station list, etc. It doesn't block and wait for the network at that point, so the rest of your startscript commands will probably just fail. At that point you are doubly inconvenienced since your music doesn't start playing right away AND you have to relogin your Pandora user.

I'll check with Perette whether there's an easy way to improve on this behavior, but let's try to get the init script set up to work around (i.e. wait for network) for now.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sun May 05, 2013 12:48 am

Ok, using a different raspberry pi at home. Configuration is not the same as the office.

At home I'm using wired ethernet (not wifi), using onboard audio (not C-Media USB), and I did NOT install shairport this time.

Otherwise I installed wsgw-21 and pianod-137 from source as usual.

Today I noticed "root" and "nobody" users are not in the audio group by default, and thus do not have access to the /dev/snd/* device files. At work I went ahead and did "usermod -a -G audio nobody" to give nobody access. At home I decided to change pianod.conf and add the "-n pi" flag to run as pi.

With all these changes the pi boots and starts playing immediately, wsgw is up, web UI works, etc. I'm listening to it right now.

So now I'm going to start bringing the config closer to the office - add shairport and then add wifi. And I'll see where things break.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sun May 05, 2013 2:26 am

Great; keep me posted.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sun May 05, 2013 7:38 am

I spoke too soon. I did a clean reinstall (starting from a fresh raspbian image) to make sure I could reproduce the success, and no luck. Once again I have a system that boots with pianod process running but silent. The web client shows an error message in red at the bottom of the page ("no channel selected" or something along those lines). If I restart pianod manually then songs start playing as expected.

I added $network and $named to the start/stop conditions in the init scripts, with no change. I tried "update-rc.d pianod defaults 95" but in spite of the man page that doesn't create symlinks like /etc/rc2.d/S95pianod as expected ...

In other words I still have exactly the problem I originally posted.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sun May 05, 2013 5:09 pm

I would guess that if you log in with netcat after the semi-failed boot up you'll see that the Pandora user isn't logged in, and so the station list is empty. Can you confirm that?

You could just change the rc.d links to S95 manually? Another workaround might be to put pianod in rc-local. Sorry for the trouble; I'll look around for more info on sequencing Raspbian services.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sun May 05, 2013 8:44 pm

Well, the html5 client shows the pandora user is logged in and there is a station list. If I select a station the track view seems to update, eg there is a thumbnail for a song. However if I try to play the track, that's when I get the "station not selected" error at the bottom of the web page. The error doesn't make sense.

When running as a service, how do I redirect stderr logging to somewhere I can see?

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sun May 05, 2013 9:02 pm

Ah, okay, that does sound more like a problem with access to the sound device. Did you try adding the alsa/pulseaudio dependencies to the init script? Or as you said, just trying to move the pianod init to S95 or later? Do you have anything else running that might be blocking up the sound device?

Unfortunately I haven't found a good way to get output from init scripts other than editing the script to redirect output to a file. Make sure you redirect STDOUT and STDERR.

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Sun May 05, 2013 10:38 pm

I do recommend logging in with netcat also, as this will give you better feedback. I think "No station selected" is just the last log message that you are probably getting, but there are probably a few earlier messages like "Player error" that are getting lost behind "No station selected" in the websockets client.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Mon May 06, 2013 4:46 am

Yes, I have "Should-Start: alsa-utils pulseaudio" in the pianod init script.

After booting I can connect as admin and set a station. When I play, however, I see "admin resumed playback" followed immediately by "track complete" and then "no station selected", see below.

Code: Select all

$ nc 10.0.0.18 4445
200 Connected
100 pianod 137. Welcome!
141 Volume: 0
108 No station selected
103 Stopped
user admin admin
132 admin signed in
200 Success
136 Privileges: admin owner service influence tuner
select station madonna
132 admin selected the station: Madonna
109 SelectedStation: station Madonna
200 Success
play
200 Success
132 admin resumed playback
105 Track playback complete
108 No station selected
103 Stopped
503 Service shutting down
If I restart the pianod service then connect with nc again, all is well.

Code: Select all

$ nc 10.0.0.18 4445
200 Connected
100 pianod 137. Welcome!
141 Volume: 0
109 SelectedStation: mix QuickMix
101 00:02/05:32/-05:29 Playing
111 ID: 286b84bc981bebcab6506fa3fac43f83cca8165156fab56fece4a1267cf432cbdc4bdffa5a63c96c9025c489223c25b65c92bcdf0270b4f3fe25eccc2d775c3d
112 Album: Riot! 
113 Artist: Cookie Monsta
114 Title: Level Up
118 CoverArt: http://cont-ch1-1.pandora.com/images/public/amz/1/1/5/7/800017511_500W_500H.jpg
115 Station: Daft Punk Radio
116 Rating: neutral
117 SeeAlso: http://www.pandora.com/cookie-monsta/riot/level-up?dc=232&ad=1:45:1:91202::0:0:0:0:803:003:CA:06037:0:0:0:0
120 UserRating: neutral
I'm not having any luck with stderr redirection. I know I'm just being dense but can you post the necessary diffs for /etc/init.d/pianod?

thanks

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Mon May 06, 2013 4:57 am

I'll have to mess with it a bit myself to figure it out; should get to this tomorrow night. The behavior you describe is exactly what I get if there's a problem accessing the sound device, e.g. if I'm already playing something through MPD and then try to play pianod.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Mon May 06, 2013 3:45 pm

Ok thanks.

There is nothing else accessing the audio device as far as I know. This is a vanilla raspbian image, latest available, with pianod and wsgw and their associated dependencies. That's it.

I even bothered to script the config so I can easily reproduce -- when I get a chance I'll post that on bitbucket or GitHub.

Gonewest
Posts: 12
Joined: Wed May 01, 2013 1:31 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Mon May 06, 2013 9:37 pm

Here's a repo containing the setup script:
https://bitbucket.org/gonewest/pianod-on-raspberrypi

Run "pi-piano.sh" as root. Don't run pi-shairport.sh; I'm saving that for later.

Note, however, I haven't updated this script to incorporate any of your suggested edits to /etc/init.d/pianod, for instance the requirements on $network, $named, alsa-utils, pulseaudio, ...

Chinasaur
Posts: 116
Joined: Tue Sep 11, 2012 10:15 pm

Re: pianod+wsgw: Pandora client/server with nice web interfa

Mon May 06, 2013 10:17 pm

If those init hint edits don't change the S-order then they probably don't matter. But did you try changing it to S95 manually? I'm starting to run out of ideas for good solutions, so maybe time to start trying some hacks, at least to confirm what's going on. Want to put a sleep line in the init script to delay pianod startup? Hopefully you can do it in a way that won't block other startup.

I'll work on getting the console output when I have a chance; may not be until tomorrow now, sorry!

Return to “Media centres”