Close
0%
0%

Podcast reader alarm clock

Bash script to use a Raspberry pi as a podcast alarm-clock

Similar projects worth following
I recently moved from Paris to Kourou to work in the space center.
As awesome as working as an engineer during rocket launch could be, I ended up very frustrated :
I can no longer listen to the morning program of my favorite station when I wake up.
The problem is not the radio reception, France INTER has a nationwide coverage which include oversees territory, but timezone difference (4 hours). I end up waking up with the midday program, completely unacceptable.

After trying different strategies (using various apps, waking up earlier, trying to enjoy the midday program or even the local radio) I had to do it the hard way.

Everything runs on a Raspberry pi 3 because I had one available and because the Wi-Fi connection is really convenient. It can run on any Linux device (I guess...)
LCD screen is useless.


  • First, burn a SD card with the apropriate Debian Image the last recommanded one)
  • Activate the SSH by adding an empty file named SSH in the root of the SD card
  • Setup the Pi to work on your network (plug a cable or configure the wifi using the GUI)
  • Connect any kind of speaker
  • Connect to the board using a SSH client (putty) (You can get your device IP by searching in your router's admin pages)
  • Use the default Login/PWD to acces (promise to yourself that you will change the password some day)
  • Create the script file
cd /home/pi/Documents
sudo nano 7-9_player.sh
  • In the file type (or copy/paste the following code)
DATE=`date +%d.%m.%Y`
cd /home/pi/Documents/
rm rss_10241.xml
wget http://radiofrance-podcast.net/podcast09/rss_10241.xml
FILENAME_PATTERN="10241-"$DATE"-ITEMA_[[:alnum:]]*-[[:alnum:]]*.mp3"
PATTERN="http://media.radiofrance-podcast.net/podcast09/10241-"$DATE"-ITEMA_[[:alnum:]]*-[[:alnum:]]*.mp3"
MP3_ADDRESS=`grep $PATTERN rss_10241.xml -o`
FILNAME=`grep $FILENAME_PATTERN rss_10241.xml -o`
wget $MP3_ADDRESS

heure=`date +%H`
while [ $heure -lt 9 ]
do
#echo "waiting hour"
heure=`date +%H`
done

minute=`date +%M`
while [ $minute -lt 30 ]
do
#echo "waiting minute"
heure=`date +%M`
done
echo "running"

omxplayer $FILNAME
rm rss_10241.xml
rm $FILNAME

Note that the wake up time is set in UTC, Kourou is in the UTC-3, which means that I want to wake up at 6:30

  • Type CTRL+X then Y to save and quit
  • Gives the execution write to the file
sudo chmod 777 7-9_player.sh
  • Edit the scheduled task to start the scipt every morning (at least 30min before the wake up time, the internet could be slow)
sudo crontab -e
  • Add the following line then save and quit
0 9 * * * /home/pi/Documents/7-9_player.sh
Note that the pi time is UTC.

My radio program ends at 9 Paris time which means 8UTC in winter and 7UTC in summer, I think the podcast is available within the hour, so I start the script at 9UTC.

  • Everything is setup, it should work in the morning.

x-shellscript - 34.00 bytes - 11/26/2017 at 16:47

Download

x-shellscript - 456.00 bytes - 11/26/2017 at 16:47

Download

x-shellscript - 210.00 bytes - 11/26/2017 at 16:47

Download

  • Modification to use an Orange Pi Zero

    hobbie05/28/2017 at 19:21 0 comments

    To use the script on an orange pi zero, few modifications need to be made :

    First use a different player : MPG123 is good

    sudo apt-get install mpg123

    in the script : use mpg123 instead of omxplayer :

    #omxplayer $FILNAME
    mpg123 $FILNAME

    As the player is compatible with alsa, add a line to set the volume in the 7-9_player.sh (anywhere before starting the player) :

    amixer sset 'Lineout volume control' 65%

    Without the extention board, the audio output is not filtered, a RC filter might be needed.

    The wifi configuration has to be set manually :

    sudo nano /etc/network/interfaces
    #----------------------------------
    #COPY
    #----------------------------------
    auto lo
    iface lo inet loopback
    
    auto eth0
    allow-hotplug eth0
    iface eth0 inet dhcp
    
    allow-hotplug wlan0
    iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
    iface default inet dhcp
    #---------------------------------
    #Ctrl + O
    #Enter
    #Ctrl + X
    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
    
    #----------------------------------
    #COPY
    #----------------------------------
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
    ssid="WIFI_MaBox"
    psk="------------------"
    }
    
    #----------------------------------
    #Change based on your WiFi Settings
    #Ctrl + O
    #Enter
    #Ctrl + X
    sudo reboot

  • Script explanation

    hobbie04/07/2017 at 21:41 0 comments

    Put the current day, month, year in a string using the format dd.mm.yyyy

    DATE=`date +%d.%m.%Y`
    

    Select the script directory, the user must have the write permition so it won't crash when launched by CRON

    cd /home/pi/Documents/
    

    Remove the old rss file, you don't want to use outdated data

    rm rss_10241.xml
    

    Get the new rss file, it will be saved as rss_10241.xml in the active directory (that's why we need writing right)

    The podcast file will have a new name everyday, this name will include the date.

    wget http://radiofrance-podcast.net/podcast09/rss_10241.xml
    

    Create a pattern to find the podcast in the rss file, note that alnum is used because those numbers can't be deducted from the date (they appear to be random but increasing)

    FILENAME_PATTERN="10241-"$DATE"-ITEMA_[[:alnum:]]*-[[:alnum:]]*.mp3"
    

    Create a pattern to find the complete address of the pod cast

    PATTERN="http://media.radiofrance-podcast.net/podcast09/10241-"$DATE"-ITEMA_$
    

    Find the adress in the rss file using the pattern

    MP3_ADDRESS=`grep $PATTERN rss_10241.xml -o`
    

    Find the exact filename using the second pattern

    FILNAME=`grep $FILENAME_PATTERN rss_10241.xml -o`
    

    Get the file ! this can take a while depending of your internet speed

    wget $MP3_ADDRESS
    

    Wait until it's wake up time (badly made...)


    heure=`date +%H` while [ $heure -lt 9 ] do #echo "waiting hour" heure=`date +%H` done minute=`date +%M` while [ $minute -lt 30 ] do #echo "waiting minute" heure=`date +%M` done echo "running"

    Play the file, wake up, have breakfast,...

    omxplayer $FILNAME
    

    Clean before leaving, it's common courtesy

    rm rss_10241.xml
    rm $FILNAME
    

View all 2 project logs

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates