Not so long ago (actually, a weekend or two ago), I was presented with a real-life issue – an issue that needs to be taken care of… ASAP!
Production was suffering. Production of high-quality foods in my mom’s kitchen, that is! 🙂
So, what was the issue?
To better help you understand the issue, we need to introduce you to the environment first – there’s my mom’s kitchen, from where many amazing dishes come out on a daily basis.
And there’s a small FM radio in this kitchen, providing her company when cooking alone – nothing special, but it’s an essential part of the kitchen (and the overall cooking process)!
About two weekends ago, the user (mom) starts complaining that the radio is having issues with the reception of her favorite FM station. It’s not good when users start complaining, of course. Especially if they are the important ones!
If this isn’t taken care of, production (of food) may suffer! 🙂
So, let’s solve the issue.
As nothing has changed from the FM radio perspective, it seems that the issue is somewhere else. After a short research, it seems that adding a new frequency to the user’s favorite radio station somehow impacted the remaining two (one of which we were using)… and now we’re having bad reception.
Tried to switch to the other two frequencies… didn’t help. This station is transmitted in at least three frequencies, but none of it provides us a good reception anymore.
Even tried with another antenna… no luck.
Switching to another radio station… is not an option. 🙂
When I was thinking about other options, I remembered that this radio station also streams over the Internet (like the example I’m using below)!
Splendid!
As I had this spare Raspberry Pi just standing there, collecting dust, an idea was born – turn it into the “Internet radio”!
The initial solution needs to be basic as possible, headless, work as soon as connected, wireless (as much as possible), and stream the radio station in question. Rather than ditching the FM radio, I’ll use it for the output part – so, Raspberry Pi’s 3,5mm output as an input to the AUX IN of the FM radio, using its amplifier and speakers (switching to AUX input is just one click away, which is fine).
I started by preparing my Raspberry Pi:
- downloaded Raspberry Pi Imager
- used it to download and customize the Raspbian image (Raspberry PI OS (32-bit)):
- set hostname
- enabled SSH
- set username and password
- configured wireless LAN
- configured locale settings
- booted my Raspberry Pi and did additional configuration via the included raspi-config utility:
- configured System Options – Boot/Auto Login – Console Autologin
- configured some other tiny things (like extending the storage, etc.)
Now it seems that I’m prepared for bringing up the “software part”.
After some reading and trying things out, I decided to go with VLC Player.
Now I just need to make it play what I want, play it on power on and without any other interaction.
Luckily, it’s not thaaat hard! 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
### check that you have your radio station's stream address (the right one)! ### i'll use https://audio.radio-banovina.hr:9998/stream, not https://www.radio-banovina.hr/uzivo/ # install all updates: sudo apt update && sudo apt dist-upgrade -y # install VLC (if not already): sudo apt install vlc -y # when I tried to play the stream, I got an error stating that the TLS certificate is not trusted # so, I downloaded and copied CA (AlphaSSL CA - SHA256 - G2) and Root CA (GlobalSign Root CA) certificates into the /usr/local/share/ca-certificates/: sudo cp *.crt /usr/local/share/ca-certificates/* # and updated the certificates in use: sudo update-ca-certificates # that took care of the TLS error and stream could finally run: vlc https://audio.radio-banovina.hr:9998/stream |
Great! That works if I manually start it… and there are no issues.
For the autostart part, I’m choosing to run it as a service, so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
### create the service file /etc/systemd/system/runRadio.service: sudo nano /etc/systemd/system/runRadio.service ### inside the file, insert something like this: [Unit] Description=runRadio [Service] User=tomica Environment="DISPLAY=:0" ExecStartPre=/bin/sleep 30 ExecStart=/usr/bin/vlc -I dummy "https://audio.radio-banovina.hr:9998/stream" WorkingDirectory=/home/tomica Restart=always [Install] WantedBy=multi-user.target ### to register this service, I'm using standard commands: sudo systemctl enable runRadio.service sudo systemctl start runRadio.service sudo systemctl status runRadio.service ### tips: ### - VLC shouldn't start with 'root', so this is why I'm using a user 'tomica' ### - -I dummy is something I learned during troubleshooting - it doesn't work (as a service) without specifying the correct (I)nterface! ### - also, I'm using sleep 30 to make sure everything is up before starting a player (could be nicer, but... works!) |
And… that’s it!
With a few hits and misses, there’s finally a simple wireless Internet radio, which starts playing once Raspberry Pi powers on (and connects to WiFi, and waits for 30 seconds, of course)! No more bad FM reception and the user is satisfied! 🙂
Cheers!