A Raspberry Pi-based music player + FM transmitter, originally created for my home alarm clock. pi-fm-player
continuously transmits MP3s stored locally, in a random order, on the FM frequency of your choice.
Connect a ~20cm/8in single-conductor wire to GPIO 4 (which is pin 7 on header P1) to act as an antenna.
On the Raspberry Pi:
- Place the
pifm
directory from this repo at a location of your choosing.- I placed it in
/opt
on my Raspberry Pi. - You may wish to adjust file permissions if installing it in
/opt
or similar. I did this by runningsudo chown -R root:root /opt/pifm
.
- I placed it in
- Put MP3 files in a directory of your choice.
- I'm using Syncthing to sync music to
~/Music
on my Pi.
- I'm using Syncthing to sync music to
- Setup
pifm-player.service
, the systemd service which runs the transmitter.- First, customize
pifm-player.service
. - Set the environment variables
MUSIC_DIR
andPIFM_BIN
to point to the music directory and thepifm
binary on your system. - Set the variable
PIFM_FREQ
to change to a different FM frequency. sudo mv pifm-player.service /etc/systemd/system/
sudo chmod 0644 /etc/systemd/system/pifm-player.service
- First, customize
- Finally, enable and run the transmitter service:
sudo systemctl enable pifm-player.service
sudo systemctl start pifm-player.service
Is it working?
sudo journalctl -f -u pifm-player.service
What was playing at some point in the past?
sudo journalctl -u pialarm-transmit.service --since "2019-10-21 07:30:00" --until "2019-10-21 07:50:00"
You can use runner
and an Uptime Kuma push monitor to get alerted if/when the pi-fm service fails. After installing runner
, put the following in /etc/cron.d/pifm-check
:
* * * * * root runner -job-name pifm-check -retries 2 -retry-delay 15 -success-notify "https://my-uptime-kuma-host.example.com:9001/api/push/1234abcd?status=up&msg=OK&ping=" -- systemctl is-active --quiet service pifm-player.service
Released under the Unlicense (see LICENSE
in this repo).
Chris Dzombak