Announcement

Collapse
No announcement yet.

[piCorePlayer] Turn off USB output when turning off player?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    uhubctl posted.
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

    Comment


      #17
      Originally posted by paul- View Post
      uhubctl posted.
      Thanks for posting it Paul. I was about to post that I couldn't get it working on my Pi 3B but it turns out that the info posted here
      https://github.com/mvp/uhubctl#raspberry-pi-b2b3b
      is incorrect. It states that all the USB ports on the Pi3B are linked together and controlled by Port 2. In fact they are controlled separately and turning off port 2 does not turn off ports 2-5. Turning off port 4 works for me.
      Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
      Bedroom: Radio
      Bathroom: Radio

      Comment


        #18
        Originally posted by slartibartfast View Post
        Thanks for posting it Paul. I was about to post that I couldn't get it working on my Pi 3B but it turns out that the info posted here
        https://github.com/mvp/uhubctl#raspberry-pi-b2b3b
        is incorrect. It states that all the USB ports on the Pi3B are linked together and controlled by Port 2. In fact they are controlled separately and turning off port 2 does not turn off ports 2-5. Turning off port 4 works for me.
        Hmm my commands work when I ssh into the pCP but not from the script. I am putting
        -S /home/tc/usb-power-on-off.sh
        in Various Options on the Squeezelite settings page. My script file is
        Code:
        #!/bin/sh
        #----------------------------------------------------------------------------------------
        # Script for turning RPi3 USB output on/off when Squeezelite player is turned on/off.
        # This script requires that extension uhubctl.tcz is installed.
        # Enter the path to this "Power On/Off Script" on the pCP Squeezelite Settings page.
        # https://github.com/mvp/uhubctl#raspberry-pi-b2b3b
        #----------------------------------------------------------------------------------------
        # squeezelite -S /home/tc/usb-power-on-off.sh
        # 
        # squeezelite sets $1 to:
        #	0: off
        #	1: on
        #----------------------------------------------------------------------------------------
        
        case $1 in
            0) uhubctl -l 1-1 -p 4 -a 0 >/dev/null 2>&1 ;;
            1) uhubctl -l 1-1 -p 4 -a 1 >/dev/null 2>&1 ;;
        esac
        Any idea what I am doing wrong?
        Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
        Bedroom: Radio
        Bathroom: Radio

        Comment


          #19
          Likely need to reference the full path to the binary.

          /usr/local/sbin/uhubctl
          piCorePlayer a small player for the Raspberry Pi in RAM.
          Homepage: https://www.picoreplayer.org

          Please donate if you like the piCorePlayer

          Comment


            #20
            Originally posted by sisiko View Post
            Following the cited thread, I created the following script file:

            Code:
            #!/bin/sh
            #----------------------------------------------------------------------------------------
            # Script for turning RPi4 USB output on/off when Squeezelite player is turned on/off.
            # This script requires that extension uhubctl.tcz is installed.
            # Enter the path to this "Power On/Off Script" on the pCP Squeezelite Settings page.
            # [url]https://github.com/mvp/uhubctl#raspberry-pi-4b[/url]
            #----------------------------------------------------------------------------------------
            # squeezelite -S /home/tc/usb-power-on-off.sh
            # 
            # squeezelite sets $1 to:
            #	0: off
            #	1: on
            #	2: initialising
            #----------------------------------------------------------------------------------------
            
            case $1 in
                0) uhubctl -l 2 -a 0 >/dev/null 2>&1 ;;
                1) uhubctl -l 2 -a 1 >/dev/null 2>&1 ;;
                2) uhubctl -l 2 -a 1 >/dev/null 2>&1 ;;
            esac
            also copied it in the folder /home/tc and linked it in the pCP Squeezelite Settings page under "Power On/Off Script".

            Here is what it does for me:

            "Play" powers up my speakers and plays music.
            "Pause" pauses the music and leads to my speakers being shut down.

            "Power on/off" the player in LMS does not reliably lead to my speakers being power on/off.

            Using the "uhubctl -l 2 -a 0 >/dev/null 2>&1" "/ uhubctl -l 2 -a 1 >/dev/null 2>&1" command loged in my piCorePlayer via SSH always works as expected.
            1. I am fine with "Play/Pause" causing my speakers to turn on/off but I expected this solution to work with "Power on/off" in LMS.
            2. "2: initialising": do I really need that line in my script or can I leave it out?
            Hi sisiko, I have modified your script to work with my Pi3 but while the power on/off commands work via an ssh connection to pCP I cannot seem to get the script to do anything. Any ideas how to troubleshoot this?
            Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
            Bedroom: Radio
            Bathroom: Radio

            Comment


              #21
              Originally posted by paul- View Post
              Likely need to reference the full path to the binary.

              /usr/local/sbin/uhubctl
              I tried
              Code:
              #!/bin/sh
              #----------------------------------------------------------------------------------------
              # Script for turning RPi3 USB output on/off when Squeezelite player is turned on/off.
              # This script requires that extension uhubctl.tcz is installed.
              # Enter the path to this "Power On/Off Script" on the pCP Squeezelite Settings page.
              # https://github.com/mvp/uhubctl#raspberry-pi-b2b3b
              #----------------------------------------------------------------------------------------
              # squeezelite -S /home/tc/usb-power-on-off.sh
              # 
              # squeezelite sets $1 to:
              #	0: off
              #	1: on
              #----------------------------------------------------------------------------------------
              
              case $1 in
                  0) /usr/local/sbin/uhubctl -l 1-1 -p 4 -a 0 >/dev/null 2>&1 ;;
                  1) /usr/local/sbin/uhubctl -l 1-1 -p 4 -a 1 >/dev/null 2>&1 ;;
              esac
              with no luck. How can I tell the state of squeezelite ($1)?
              Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
              Bedroom: Radio
              Bathroom: Radio

              Comment


                #22
                Originally posted by paul- View Post
                Likely need to reference the full path to the binary.

                /usr/local/sbin/uhubctl
                I also tried the built in "powerscript.sh" which sends the $1 state to an ssh terminal and that doesn't work either. Am I wrong in expecting that toggling the power of piCorePlayer in Material skin or the Default skin should change the state of $1 and display it in the terminal?
                Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
                Bedroom: Radio
                Bathroom: Radio

                Comment


                  #23
                  Originally posted by slartibartfast View Post
                  I also tried the built in "powerscript.sh" which sends the $1 state to an ssh terminal and that doesn't work either. Am I wrong in expecting that toggling the power of piCorePlayer in Material skin or the Default skin should change the state of $1 and display it in the terminal?
                  Just in case the arg num is wrong you should dump all args values into a file - something like

                  echo "All Arguments values:" [email protected] >/tmp/allargs.txt

                  Comment


                    #24
                    Originally posted by bpa View Post
                    Just in case the arg num is wrong you should dump all args values into a file - something like

                    echo "All Arguments values:" [email protected] >/tmp/allargs.txt
                    Do you mean edit the script file or is there another way to do it?

                    Sent from my Pixel 3a using Tapatalk
                    Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
                    Bedroom: Radio
                    Bathroom: Radio

                    Comment


                      #25
                      Originally posted by bpa View Post
                      Just in case the arg num is wrong you should dump all args values into a file - something like

                      echo "All Arguments values:" [email protected] >/tmp/allargs.txt
                      I tried running that at the command line and it doesn't list any arguments in the file. How do I get it to dump the arg values?

                      Sent from my Pixel 3a using Tapatalk
                      Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
                      Bedroom: Radio
                      Bathroom: Radio

                      Comment


                        #26
                        My suggestion is in the script.

                        The following is my version which just creates lots of output to shows which parts of script are executed.
                        Squeezelite V1.9.7-1283 was tested on a Rasbian Buster
                        Squeezelite is standard Ralphy and has GPIO build option.
                        Run from command line with "-S /home/pi/myscript.sh"

                        Code:
                        #!/bin/sh
                        #----------------------------------------------------------------------------------------
                        # Script for turning RPi3 USB output on/off when Squeezelite player is turned on/off.
                        # This script requires that extension uhubctl.tcz is installed.
                        # Enter the path to this "Power On/Off Script" on the pCP Squeezelite Settings page.
                        # https://github.com/mvp/uhubctl#raspberry-pi-b2b3b
                        #----------------------------------------------------------------------------------------
                        # squeezelite -S /home/tc/usb-power-on-off.sh
                        # 
                        # squeezelite sets $1 to:
                        #	0: off
                        #	1: on
                        #----------------------------------------------------------------------------------------
                        NOW=$(date +"%m-%d-%Y %T")
                        echo "---  $NOW ---" >>/tmp/powerlog.txt
                        echo "Args: " "[email protected]" >>/tmp/powerlog.txt
                        case $1 in
                            0) echo "Arg dollar 1 value 0 " >>/tmp/powerlog.txt ;;
                            1) echo "Arg dollar 2 value 1 " >>/tmp/powerlog.txt ;;
                        esac
                        
                        echo "---- End run ---- " >>/tmp/powerlog.txt
                        Toggling power button on WebUI for player
                        Code:
                        ---  11-15-2020 11:49:12 ---
                        Args:  0
                        Arg dollar 1 value 0 
                        ---- End run ---- 
                        ---  11-15-2020 11:49:12 ---
                        Args:  1
                        Arg dollar 2 value 1 
                        ---- End run ---- 
                        ---  11-15-2020 11:49:13 ---
                        Args:  0
                        Arg dollar 1 value 0 
                        ---- End run ---- 
                        ---  11-15-2020 11:49:13 ---
                        Args:  1
                        Arg dollar 2 value 1 
                        ---- End run ----

                        Comment


                          #27
                          Originally posted by bpa View Post
                          My suggestion is in the script.

                          The following is my version which just creates lots of output to shows which parts of script are executed.
                          Squeezelite V1.9.7-1283 was tested on a Rasbian Buster
                          Squeezelite is standard Ralphy and has GPIO build option.
                          Run from command line with "-S /home/pi/myscript.sh"

                          Code:
                          #!/bin/sh
                          #----------------------------------------------------------------------------------------
                          # Script for turning RPi3 USB output on/off when Squeezelite player is turned on/off.
                          # This script requires that extension uhubctl.tcz is installed.
                          # Enter the path to this "Power On/Off Script" on the pCP Squeezelite Settings page.
                          # https://github.com/mvp/uhubctl#raspberry-pi-b2b3b
                          #----------------------------------------------------------------------------------------
                          # squeezelite -S /home/tc/usb-power-on-off.sh
                          # 
                          # squeezelite sets $1 to:
                          #	0: off
                          #	1: on
                          #----------------------------------------------------------------------------------------
                          NOW=$(date +"%m-%d-%Y %T")
                          echo "---  $NOW ---" >>/tmp/powerlog.txt
                          echo "Args: " "[email protected]" >>/tmp/powerlog.txt
                          case $1 in
                              0) echo "Arg dollar 1 value 0 " >>/tmp/powerlog.txt ;;
                              1) echo "Arg dollar 2 value 1 " >>/tmp/powerlog.txt ;;
                          esac
                          
                          echo "---- End run ---- " >>/tmp/powerlog.txt
                          Toggling power button on WebUI for player
                          Code:
                          ---  11-15-2020 11:49:12 ---
                          Args:  0
                          Arg dollar 1 value 0 
                          ---- End run ---- 
                          ---  11-15-2020 11:49:12 ---
                          Args:  1
                          Arg dollar 2 value 1 
                          ---- End run ---- 
                          ---  11-15-2020 11:49:13 ---
                          Args:  0
                          Arg dollar 1 value 0 
                          ---- End run ---- 
                          ---  11-15-2020 11:49:13 ---
                          Args:  1
                          Arg dollar 2 value 1 
                          ---- End run ----
                          I am using squeezelite v1.97-1282-pCP
                          Running -S /home/tc/myscript.sh doesn't work from command line. I see "-sh: -S: not found"
                          Adding it as a script in pCP also doesn't seem to do anything. Maybe my scripts aren't running for some reason.
                          Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
                          Bedroom: Radio
                          Bathroom: Radio

                          Comment


                            #28
                            Originally posted by slartibartfast View Post
                            I am using squeezelite v1.97-1282-pCP
                            Running -S /home/tc/myscript.sh doesn't work from command line. I see "-sh: -S: not found"
                            Adding it as a script in pCP also doesn't seem to do anything. Maybe my scripts aren't running for some reason.
                            You don't show your command line

                            The first line indicates which shell to use. IIRC pcp doesn't have a shell it uses busybox - so there may be no "/bin/sh"

                            There is a pcp extension called bash.tcz whic may provide "/bin/bash "which may also then create a link to "/bin/sh"

                            For example if I change the first line on my system to "#!/bin/badshell" I get the following message
                            Code:
                            sh:  1:  /home/pi/myscript.sh:  not found
                            Last edited by bpa; 2020-11-15, 21:06. Reason: Correct shell paths

                            Comment


                              #29
                              Originally posted by bpa View Post
                              You don't show your command line

                              The first line indicates which shell to use. IIRC pcp doesn't have a shell it uses busybox - so there may be no "/usr/sh"

                              There is a pcp extension called bash.tcz whic may provide "/usr/bash "which may also then create a link to "/usr/sh"

                              For example if I change the first line on my system to "!/usr/badshell" I get the following message
                              Code:
                              sh:  1:  /home/pi/myscript.sh:  not found
                              I found a forum post saying that pCP comes with sh. Is that a bash alternative?

                              Sent from my Pixel 3a using Tapatalk
                              Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
                              Bedroom: Radio
                              Bathroom: Radio

                              Comment


                                #30
                                Originally posted by bpa View Post
                                You don't show your command line

                                The first line indicates which shell to use. IIRC pcp doesn't have a shell it uses busybox - so there may be no "/usr/sh"

                                There is a pcp extension called bash.tcz whic may provide "/usr/bash "which may also then create a link to "/usr/sh"

                                For example if I change the first line on my system to "!/usr/badshell" I get the following message
                                Code:
                                sh:  1:  /home/pi/myscript.sh:  not found
                                If I run
                                /home/tc/my script.sh
                                without the -S
                                I get
                                /home/tc/my script.sh: line 17: syntax error: unexpected word (expecting "in")

                                Sent from my Pixel 3a using Tapatalk
                                Living Room: Touch or Squeezelite (Pi3B) > Topping E30 > Audiolab 8000A > Monitor Audio S5 + BK200-XLS DF
                                Bedroom: Radio
                                Bathroom: Radio

                                Comment

                                Working...
                                X