Skip to content

cdzombak/pi-fm-player

Repository files navigation

pi-fm-player

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.

Hardware Setup

Connect a ~20cm/8in single-conductor wire to GPIO 4 (which is pin 7 on header P1) to act as an antenna.

Install & Configure

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 running sudo chown -R root:root /opt/pifm.
  • Put MP3 files in a directory of your choice.
    • I'm using Syncthing to sync music to ~/Music on my Pi.
  • Setup pifm-player.service, the systemd service which runs the transmitter.
    • First, customize pifm-player.service.
    • Set the environment variables MUSIC_DIR and PIFM_BIN to point to the music directory and the pifm 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
  • Finally, enable and run the transmitter service:
    • sudo systemctl enable pifm-player.service
    • sudo systemctl start pifm-player.service

Logs

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"

Monitoring

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

License

Released under the Unlicense (see LICENSE in this repo).

Author

Chris Dzombak

About

Raspberry Pi FM transmitter that plays music forever from the local filesystem.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •