dsheli
Posts: 1
Joined: Sun May 26, 2019 1:42 am

Cut power to USB ports w/ Python

Sun May 26, 2019 1:51 am

Hello everyone!

I am working on a solar Pi timelapse rig and need to save power between shots. Killing power to the USB ports will cut my power consumption by almost 1 watt. I am able to successfully kill power with the following commands in bash:
Power off:
echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
Power on:
echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/bind

I am new to Python and would like for this script to be run in my Python script that is controlling the camera. I thought I would use the subprocess command but I am not having any luck.

subprocess.call(['echo','1-1|sudo tee /sys/bus/usb/drivers/usb/unbind'],shell=True)

Any thoughts?

Andyroo

Re: Cut power to USB ports w/ Python

Sun May 26, 2019 12:07 pm

I think it is because the subprocess captures stdin and stdout for itself rather than pass them through to the second part of the command.

A couple of thought (no Pi handy to try at the mo):

1) Try the Popen command from the same module
2) Create a little bash script that takes on / off as a parameter and just call that.

ghp
Posts: 1418
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Cut power to USB ports w/ Python

Sun May 26, 2019 2:20 pm

Code: Select all

try:
    subprocess.call( "echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/unbind", shell=True)
except ItIsASunnySundayAndNotWorkingAtAllException:
    pass

ankith26
Posts: 103
Joined: Mon Mar 25, 2019 11:08 am
Location: Earth
Contact: Website

Re: Cut power to USB ports w/ Python

Sat Jun 01, 2019 4:38 am

os.system(....) usually works for me.
although I heard its not recommended and am not so sure
My website is at https://pratt.ml
Hope it runs (which it wont)

Return to “Python”