Turn off usb power raspberry pi on shutdown.sh

Hi,

I would like to add a function -turn off the usb power- on shutdown.sh, is it possible?
Sur

Hey, yes, looks like there’s an utility that could control the USB power: https://github.com/mvp/uhubctl

Then you’d simply add the call to the utility in the shutdown.sh script before the sudo shutdown now line.

Hi @Giedrius Thanks :slight_smile: I add the line but it doesn’t work. I am using rpi 3b+
I changed the script on here: /usr/local/pisound/scripts/pisound-btn/shutdown.sh

. /usr/local/pisound/scripts/common/common.sh

log “Pisound button held for $2 ms, after $1 clicks!”

if [ $1 -ne 1 ]; then
log “Ignoring hold after $1 clicks…”
exit 0
fi

aconnect -x

for i in $(seq 1 10); do
flash_leds 1
sleep 0.1
done

log “Shutting down.”

uhubctl -l 1-1 -p 2 -a 0

sudo shutdown now

Does uhubctl -l 1-1 -p 2 -a 0 work as expected when you run it in a terminal?

I got this patch@patchbox:~ $ uhubctl -l 1-1 -p 2 -a 0
bash: uhubctl: command not found

I tried
patch@patchbox:~ $ sudo uhubctl -l 1-1 -p 2 -a 0
sudo: uhubctl: command not found

See: https://github.com/mvp/uhubctl#compiling

Yes I done this. My steps:

  1. sudo apt-get install libusb-1.0-0-dev
  2. all is done > reboot
  3. I tried uhubctl -l 1-1 -p 2 -a 0
  4. I got bash: uhubctl: command not found

You have to also do:

git clone https://github.com/mvp/uhubctl
cd uhubctl
make
sudo make install

The installation is done. I did this:

  1. test it. sudo uhubctl -l 1-1 -p 2 -a 0
  2. it turns the usb power off
  3. edit the shutdown.sh …
    . /usr/local/pisound/scripts/common/common.sh

log “Pisound button held for $2 ms, after $1 clicks!”

if [ $1 -ne 1 ]; then
log “Ignoring hold after $1 clicks…”
exit 0
fi

aconnect -x

for i in $(seq 1 10); do
flash_leds 1
sleep 0.1
done

log “Shutting down.”

uhubctl -l 1-1 -p 2 -a 0

sudo shutdown now

  1. it turns the rpi off but not the usb power.

what did I do wrong?

Try using sudo at the start of the line in the script too.

the prev code works! I made a mistake. Thx for your help @Giedrius

1 Like