Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 2 of 2
  1. #1
    Senior Member DJanGo's Avatar
    Join Date
    Sep 2005
    Location
    Germany
    Posts
    2,371

    autoplay when rpi is powered on

    I have a Rpi with Raspbian /squeezelite in my Man cave and wanted that this Player starts to play when its powered on.

    Instead of using some "Magic" inside the LMS Server i want to use the simplest way that didnt need resources all the time.

    /edit
    added some handling to support older and newer squeezelite Versions.

    Code:
    #! /bin/sh
    
    ###vars:
    ## the mac from your RPI/squeezelite session
    playerID="CA:FE:04:DJ:AN:G0"
    
    ## The Backup Playlist when the actual playlist is empty.
    ## The Path must be the exact path where your lms finds the playlist!
    my_playlist="/home/jan/[playlist]/mancave.m3u"
    
    ## The IP from your LMS System
    server=192.168.199.11
    
    ## The CLI Port from your LMS 
    port=9090
    
    
    ## before doing anything - we want to know tha actual Facts about the Player ;-)
    playerstatus=$(printf "$playerID power ?\nexit\n" |nc $server $port|cut -d ' ' -f 3)
    
    ## Older squeezelite Versions answer with 0 and 1 when using power?
    ## Newer Versions answers with on/off!!
    
    if [ $playerstatus = 1 ]
       then
       playerstatus=on
    fi
    
    
    if [ ! $playerstatus = on ]
       then
       echo "powering player on"
       printf "$playerID power 1\nexit\n"|nc $server $port
    else
       echo "player was on already"
    fi
    
    ## If the Player has a Playlist it should start the next Song...
    playermode=$(printf "$playerID mode ?\nexit\n" |nc $server $port|cut -d ' ' -f 3)
    if [ ! $playermode = play ]
       then
       echo "nothing to play"
       echo "try to play players playlist"
       printf "$playerID  play\nexit\n"|nc $server $port
       sleep 2
       playermode=$(printf "$playerID mode ?\nexit\n"|nc $server $port|cut -d ' ' -f 3)
       if [ ! $playermode = play ]
          then
          echo "no playlist loaded we play $my_playlist now"
          printf "$playerID playlist play $my_playlist\nexit\n"|nc $server $port
       fi
    else
       echo "playing"
    fi
    exit 0
    Save that - change the vars and make it executable with chmod +x filename.sh.

    You can add the scriptpath/scriptname to /etc/rc.local or add it in your squeezelite init script.
    Last edited by DJanGo; 2016-02-28 at 03:23. Reason: handling for older and newer squeezelite versions added

  2. #2
    Junior Member
    Join Date
    Feb 2017
    Posts
    1

    Excellent !

    Very well done! Simple and effective!

    I placed the script execution in rc.local right after the Audioplayer execution. For my RPi2 I found that I need to add a "sleep 30" command at the beginning of the script. Apparently during Squeezelite startup sequence the script will retrieve incorrect status, it believes that Squeezelite is allready on 'playing' status. Sleep command resolved this issue for me, but maybe there are other ways to solve it in a more elegant way...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •