Making my PiRadio run at startup

Oddly, the hardest thing so far has been making my Really Very Simple RaspberryPi radio start playing by itself when you turn it on. Which is really the sort of thing you expect a radio to do, really. Not much to ask, you’d think.

First I made an internet radio with some bits of rubbish lying round the house. Then my daughter and I added a button to change the station.

I’ve been going crazy trying to figure out ways of getting the radio to start of its own accord as the Pi boots up, trying to edit rc.local, using @reboot statements in crontab – none of it worked. I thought it might be permission problems, possibly I needed to reinstall mpd and mpc as a different user… Eventually I thought of looking at the mpd (music player daemon) logs – they live in /var/log/mpd/mpd.log

Here I found that the problem was a lack of network connectivity – there were lots of ‘Couldn’t resolve host’ and ‘Network is unreachable’ errors each time I rebooted. It seems that the problem is my Edimax wifi dongle, which is taking a LONG time to get on the network.

I found, by trial and error improvement, that if I added this line to /etc/rc.local:

(sleep 65; python /home/pi/

the radio starts playing – eventually – by itself when you turn the Raspberry Pi on. It takes an age to start up though, so long that by the time it starts playing a radio station you’ve almost forgotten you turned it on. So I think if we do put this in a box, we’ll need to add another button as an ‘on/off’ switch that in fact just sends an ‘mpc stop’ command and leaves the Raspberry Pi running in the background. Perhaps I can find something else of use the Pi can do in the meantime…

Also, as I already have an Arduino with an LCD shield, I quite like the look of this project using an Arduino-RaspPi combo, a bit like I did with my Fridge Gizmo.

This entry was posted in radio, Raspberry Pi, Raspbian and tagged , , , , . Bookmark the permalink.

Leave a Reply