A beautiful web radio for a living room music system


After configuring the stations, restart the service by typing,

sudo systemctl restart pi-webradio.service

then navigate to the address http://<Host>:8026/ in the browser. If the browser runs on the same system as the service, replace <Host> with localhost; otherwise, enter the IP address or name of the corresponding Raspberry Pi.

Operating the web radio is largely self-explanatory. On the left side, icons let you toggle the time, player, station selection, file selection, and tools views (see Figure 9). The Tools page is where you can stop the application, reboot, or shutdown the system. The File selection lets you play MP3 files.

The application can also record broadcasts on the fly if you press the Record button (far right in the buttonbar below the station logo). The recording will then run as long as you specified in /etc/pi-webradio.conf. In addition to spontaneous recordings, web radio also supports scheduled recordings, even independent of the Pi web radio service. To do this, install the at package and schedule the recording with a one-liner:

# echo /usr/local/bin/pi-webradio.py -r 4 120 | at 20:00 31.10.2021

The command records channel 4 for 120 minutes. The at daemon takes care of starting on time. The atq command will show you the recording queue, and atrm <number> lets you delete jobs. You might want to define regular recordings in the crontab or as systemd timers if you prefer a more modern approach.


An integrated solution with a server and browser on one system (Figure 7) poses a few additional challenges. First, is the issue of starting the browser as an application (i.e., without the usual frames, menus, and buttons of a normal web browser). Also, you want the program to launch in kiosk mode, which prevents the user from exiting; for example:

$ chromium-browser --app=http://localhost:8026/ --kiosk

To run the browser at boot time, copy the desktop file from Listing 2 to the $HOME/.config/autostart/ directory. The name does not matter, but the file needs the .desktop extension. The call to the browser is scripted in line 4; the script also terminates the browser later when you stop the radio server from the Tools page.

Listing 2

Desktop Autostart File

01 [Desktop Entry]
02 Name=Pi-Webradio
03 Comment=Webclient (Chrome) for Pi-Webradio
04 Exec=/usr/local/bin/webradio_chrome.sh
05 Terminal=false
06 Type=Application
07 StartupNotify=false
08 X-GNOME-Autostart-enabled=true

Another challenge is to hide the mouse cursor. To do this, you need the unclutter package, which takes care of the appropriate call in the startup script. The script also disables any power-saving options that would cause the screen to switch off.

Alternative Hardware

Not every piece of hardware in the Raspberry Pi universe is suitable for a web browser, which is why the Pi web server also provides a simple web API for control. The program webradio_cli.py allows complete control from the keyboard – or remotely, if desired.

The project also provides a minimalist control program for Pimoroni's Pirate Audio HATs with four buttons and a miniscreen (Figure 12). The HATs are available in different versions, among others with mono speaker or with headphone output. All variants come with a 240x240px screen and four buttons.

Figure 12: The software can also run on a Pirate Audio HAT by Pimoroni.

Again, the server and the client run on the same hardware. The client monitors the four buttons and uses them to change the station and volume. The display shows the logo of the current station. If you change the station from the web interface (e.g., from a smartphone), the client also notices this and updates the image.

The program for the Pirate HAT is a good starting point for DIY projects with other hardware, such as classic 4x20cm LCDs. More info can be found in my project repository [8].

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Nyttig

    Turn a Raspberry Pi into a useful personal micro server for streaming Internet radio, reading RSS feeds, jotting down notes, sharing files, and more.

  • FSFE and FFII to Radio Station Winners: "rOGG on"

    Radio Free Deutschland: For Document Freedom Day, March 31 2010, a couple of European radio stations were granted awards for using open standards.

  • Pi FM Radio

    Low-cost RTL-SDR dongles can read frequencies between 24 and 1,766MHz. We built a simple FM radio with a Raspberry Pi, a USB dongle based on the RTL2832U chipset, an LCD HAT, and some Python code.

  • Last.fm

    Last.fm tracks your musical tastes and helps you find users with similar interests.

  • Internet Radio Intro

    Did you think the Internet was out of revolutions? With Internet radio, anyone can be a broadcaster. If you want to start broadcasting or podcasting, or even if you're just looking for the perfect station, check out this month's Internet Radio cover story.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More