Web Radio alarm clock on Raspberry
Web agency » Digital news » Web Radio alarm clock on Raspberry

Web Radio alarm clock on Raspberry

Edit: new version available here.
In order to immerse myself a little more in English and gain competence in oral comprehension, I would like to wake up in the morning with US radios. Only here is a clock radio working with web radios costs on average around 150 €. I suggest you do it for the price of a raspberry pi. Necessary material:

  •  A Raspberry Pi 
  • A pair of speakers to connect to the Raspberry.
  • (Optional) An Android Smartphone

 

Prerequisites on the Rpi system

The good time

To display the time of your Rpi type the command

If the time is not correct it is surely that the zone is not correctly adjusted. Then type

then choose 'Europe / Paris'.

Web server

A web server to distribute the application written in HTML5 and PHP.

To check that the installation is ok, go to the address of the Rpi with our preferred browser. For me it will be IE6. The apache web server should show you the default index page like the following image. itwork

 

Audio tuning

By default on the Rpi, sound comes out through the HDMI interface. To output the sound through the analog output in order to use speakers, type the following command

Or is the output number. 0 = auto, 1 = analog, 2 = hdmi.

To force the analog output we will type

A simple sound test to verify.

You should hear a sizzle.

You can adjust the output volume of the Rpi via the command

By default the Rpi amplifies to 50%. The alsamixer command offers you an adjustment menu via the “up arrow” and down arrow ”keys on the keyboard.

Media player

The application is based on an open-source player named MPlayer. MPlayer is a multimedia player for linux. It supports most formats and also handles audio streams found on the net, which is of interest to us in our case.

mplayer is a p command line programilotee through the standard entrance.

To test it, connect a pair of speakers to the Rpi and run the following command

Updating apache privileges

The idea is therefore to piloter this program through the web interface. Only there is a problem. On nunux, each program has its own user to be launched. This for security reasons. It is normal that the user of the Apache web server (www-data) cannot execute system commands. This user therefore does not have the right to launch the MPlayer program. We will authorize the user www-data to execute certain system commands necessary for the program. For that we use sudo. Sudo allows the system administrator to grant certain users (or user groups) the ability to run a command as an administrator, or as another user. It can be finely tuned to allow or deny the execution of privileged tasks. Thanks to him, we will give the particular rights to our user www-data following:

  • Start MPlayer
  • Find out if MPlayer is running
  • Stop MPlayer

To do this, we edit the sudoer file using the command

Add the following line at the end of the file

Installation of the Piclodio application on the Rpi

I named the Piclodio app for Rapsberry Pi Clock Radio. The code is available on GitHub here.

We retrieve the latest version of the archive directly on the Rpi

We extract

We place the folder in the apache directory

We give the rights to the user of apache (www-data) on this directory

The application is installed.

Use Case

You can use the application via any browser on a terminal on your local network. Just go to the IP address of the Rpi and add the name of the piclodio folder at the end of the url like this

The application, due to its interface, is more intended for mobile terminals of the smartphone type but it works just as well on a PC browser.

 Where can I find web radio URLs?

I recommend the site http://tunein.com or http://www.radio.fr. Once you have found a web radio you just have to retrieve the url which generates the audio stream to put it in Piclodio.

On Chrome:

  • right click on the page
  • Inspect the element
  • “Network” tab
  • Find the script which transfers the most data (the one with the largest yellow bare)
  • Copy the “Request URL” in Piclodio

stream_audio_chrome

 

requestURL

Piclodio Android app

It's not great to go through the browser on your smartphone each time you want to change the alarm clock or just start the radio. You have to launch the browser then enter the url of the raspberry or go and find it in your favorites. In short, it's too long. So I made a small Android application that will simply display the Rpi web page.

The code is available on GitHub here so bearded purists can verify that I didn't unwittingly place a back door that sells their data directly on Ebay.

Otherwise you can download the apk here. At launch, the program will just ask you for the piclodio url on the Rpi.

settings_piclodiopiclodio_android

 

 

 

★ ★ ★ ★ ★