May 20, 2014

Day & Night Sampler - a raspberry pi mpd mini boombox Part 4: Starting the Boombox Automatically

See Part 3 of this project, Configure MPD Player.

Let's start making the software work together. First, copy code from github to your target raspberry pi. You should have already completed this in Part 2 of this project. You'll need the VFD.py and rpi_boombox.py scripts for the basic boombox functions. You can copy these to /home/pi.


Now we'll add software changes that make the raspberry pi act more like consumer electronics. It won't be "instant on", but it will start up in a minute or so and the rpi_boombox.py script will start shortly after that. The following script can be copied from github, it's name is rpi_boombox-init.sh. You should have already copied this in Part 2.


We need to start the main rpi_boombox.py python script at power on.
Here is the script:
### BEGIN INIT INFO
# Provides: rpi_boombox - now playing / date time /weather
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Main Menu shown on Vacuum Flourescent Display
# Description: now playing / date time /weather
### END INIT INFO


#! /bin/sh
# /etc/init.d/rpi_boombox


export HOME
case "$1" in
    start)
        echo "Starting rpi_boombox"
        /home/pi/rpi_boombox.py  2>&1 &
    ;;
    stop)
        echo "Stopping rpi_boombox"
    rpi_boombox_PID=`ps auxwww | grep rpi_boombox.py | head -1 | awk '{print $2}'`
    kill -9 $rpi_boombox_PID
    ;;
    *)
        echo "Usage: /etc/init.d/rpi_boombox.py {start|stop}"
        exit 1
    ;;
esac
exit 0

Add this script in /etc/init.d/rpi_boombox.

Reboot and the python script rpi_boombox.py in /home/pi/ should start up auto-magically!

Continue to Part 5: Hardware Configuration

No comments:

Post a Comment