How I listen to my favourite radio

4 minute read

Published:

I moved out of my country more than one year ago, and one of the things I miss the most is being able to easily listen to my favourite radio (Radio Popolare). Since the radio has a web streaming, I figured out I could use my Raspberry Pi to play it. Quite a boring story up to now. The cool (at least for me) part of it, is that I managed to plug a rocker switch to the RPi to have an easy and quick ON/OFF button to play the radio.

final result

The RPi runs Volumio, a very cool music player originally developed by Michelangelo Guarise. This means it can be used to play Spotify, music from a USB stick, AirPlay, and maybe other cool things I don’t know about. So here comes a report of what I did exactly, in case somebody wants to build something similar.

Disclaimer

I am not a programmer, nor an electronic engineer. I was a bit lazy in setting up the case. The final result doesn’t work perfectly: sometimes when turning the switch to OFF, it actually sends the ON command. I suspect it might be a matter of loose connections.

Material

Software

How to put things togheter

Software part

The OS: Volumio

First thing, download and install Volumio on the Micro SD card. You can find the instructions on Volumio’s website, just scroll down to find the guide.

Interacting with Volumio, API requests

The system I use to turn on and off the radio is rather simple; I use one API request to ask Volumio to play a specific playlist and another to stop anything that might be playing. API requests to Volumio interface are documented here.

I use a playlist to be able to play the webradio from API. I had found this idea somewhere on the web, but cannot find the page any longer. Anyway the setup goes as follows:

  1. Access Volumio interface
  2. Go to Browse, then WebRadio, and find your WebRadio
  3. On the far right, click on the three dots and click on “Clear and Play” (beware, this will clean your current queue)
  4. Go to the Queue page, and save the queue as a playlist (top right). I called my playlist “rp_autoplay”.

    This allows us to use the API request http://127.0.01:3000/api/v1/commands/?cmd=playplaylist&name=rp_autoplay to play the radio that is saved in the playlist “rp_autoplay”. The request for stopping anything from playing is: http://127.0.0.1:3000/api/v1/commands/?cmd=stop Note that the IP address (127.0.01) can be replaced by localhost.

Copy and enable rocker.py

To deal with the switch I wrote a python script that checks for changes in the state of the switch and subsequently sends the API requests to Volumio.

The script can be found here.

The module RPi.GPIO is needed and was not installed on my Volumio version so I had to install it manually:

  1. Enable ssh on Volumio by following the guide in this page.
  2. ssh to the Raspberry and install gcc and RPi.GPIO following this guide. Note that in my case /etc/apt/sources.list was already set up for jessie.
  3. wget or scp the python script to the Raspberry
  4. Enable the script to run at boot by editing /etc/rc.local, by adding the line sudo python /home/volumio/rocker.py &

    Note that the path has to be consistent with the location of the script, and the & is essential. Michelangelo Guarise says that we should use a different system to have a script run at boot, but I found that rc.local works as well.

to be continued…