OpenWrt Forum Archive

Topic: Power on/off USB ports on hubs with hub-ctrl

The content of this topic has been archived on 18 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Edit Jan 27, 2015:
hub-ctrl is now part of the OpenWrt packages feed.

It is a tiny command line tool to switch on/off individual ports' power on USB hubs that support it.

I think it would be useful if you want to connect a number of devices to your OpenWrt powered device and want them to consume power only if you use them.

(Last edited by probono on 27 Jan 2015, 01:12)

Not hub-ctrl.c, but I got hub_ctrl.py to work.

Keep in mind that you need a hub capable of per-port-power-switching for this to work.

probono wrote:

Has anyone got
http://www.gniibe.org/oitoite/ac-power- … hub-ctrl.c
to compile on OpenWrt? It is a tiny command line tool to switch on/off individual ports' power on USB hubs that support it.

I think it would be useful if you want to connect a number of devices to your OpenWrt powered device and want them to consume power only if you use them.

It looks like this tiny and cool program. I tried to manually compile it without a problem.

[debian@Debian:/opt/openwrt-svn-trunk/build_dir/target-arm_xscale_uClibc-0.9.33.2_eabi/usb-power-control/src 4160%] ~ /opt/openwrt-svn-trunk/staging_dir/toolchain-arm_xscale_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc -o hub-ctrl hub-ctrl.c -I/opt/openwrt-svn-trunk/staging_dir/target-arm_xscale_uClibc-0.9.33.2_eabi/usr/include -L/opt/openwrt-svn-trunk/staging_dir/target-arm_xscale_uClibc-0.9.33.2_eabi/usr/lib -lusb-1.0 -lusb
[debian@Debian:/opt/openwrt-svn-trunk/build_dir/target-arm_xscale_uClibc-0.9.33.2_eabi/usb-power-control/src 4161%] ~ dir
total 40
-rwxr-xr-x 1 debian users 14565 Feb 16 16:11 hub-ctrl
-rw-r--r-- 1 debian users  9270 May 16  2011 hub-ctrl.c
-rw-r--r-- 1 debian users  7644 Feb 16 16:06 hub-ctrl.o
[debian@Debian:/opt/openwrt-svn-trunk/build_dir/target-arm_xscale_uClibc-0.9.33.2_eabi/usb-power-control/src 4162%] ~ file hub-ctrl
hub-ctrl: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
[debian@Debian:/opt/openwrt-svn-trunk/build_dir/target-arm_xscale_uClibc-0.9.33.2_eabi/usb-power-control/src 4162%] ~
[debian@Debian:/opt/openwrt-svn-trunk 160%] ~ telnet 10.0.0.2
Trying 10.0.0.2...
Connected to 10.0.0.2.
Escape character is '^]'.
 === IMPORTANT ============================
  Use 'passwd' to set your login password
  this will disable telnet and enable SSH
 ------------------------------------------


BusyBox v1.19.4 (2014-02-11 23:51:11 EST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 BARRIER BREAKER (Bleeding Edge, r39577)
 -----------------------------------------------------
  * 1/2 oz Galliano         Pour all ingredients into
  * 4 oz cold Coffee        an irish coffee mug filled
  * 1 1/2 oz Dark Rum       with crushed ice. Stir.
  * 2 tsp. Creme de Cacao
 -----------------------------------------------------
root@DockStar:/# cd /usr/bin
root@DockStar:/usr/bin# scp debian@10.0.0.100:/opt/openwrt-svn-trunk/build_dir/target-arm_xscale_uClibc-0.9.33.2_eabi/hub-ctrl/src/hub-ctrl .
debian@10.0.0.100's password:
TERM: Undefined variable.
hub-ctrl                             100% 14565     50.1KB/s   00:00
root@DockStar:/usr/bin# file hub-ctrl
hub-ctrl: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
root@DockStar:/usr/bin# ls -la hub-ctrl
-rwxr-xr-x    1 root      root          14565 Feb 16 16:11 hub-ctrl
root@DockStar:/usr/bin# ./hub-ctrl
Hub #0 at 001:002
 INFO: individual power switching.
Hub #1 at 001:001
 INFO: individual power switching.
 WARN: Port indicators are NOT supported.

You can download the OpenWRT SDK for your platform and manually compile it as shown above. You will need both libusb-1.0 and libusb-compat packages which probably come with the SDK.

(Last edited by mazilo on 16 Feb 2014, 23:44)

If you need simple, but non portable solution, you can control usb power directly with gpio, see: http://wiki.openwrt.org/doc/faq/after.i … .power.off

You will have to eperiment, which gpio number does your router use for usb power control, I use wr842nd and it uses gpio6.

Hi nozombian, thanks for the hint, but I would like to switch power to the individual ports on the USB hub.

Looks like finally I got this to compile using the OpenWrt SDK.
https://github.com/probonopd/hub-ctrl-for-openwrt

This repository contains a Makefile that allows a hub-ctrl package to be built using the OpenWrt SDK. I have also uploaded a precompiled binary package for ar71xx (e.g., TP-Link TL-WR703N, TL-WR710N; D-Link DIR-505).

(Last edited by probono on 24 Dec 2014, 12:49)

how to use it?

djdeeles wrote:

how to use it?

You will see when you use it.

hub-ctrl
hub-ctrl -h
hub-ctrl -v


root@DIR-505-3:~# hub-ctrl
Hub #0 at 001:002
 INFO: ganged switching.
Hub #1 at 001:001
 INFO: individual power switching.
 WARN: Port indicators are NOT supported.
Hub #2 at 001:003
 INFO: ganged switching.
Hub #3 at 001:006
 INFO: ganged switching.
 WARN: Port indicators are NOT supported.
Hub #4 at 001:009
 INFO: individual power switching.
Hub #5 at 001:010
 INFO: individual power switching.
root@DIR-505-3:~# hub-ctrl -v
Hub #0 at 001:002
 INFO: ganged switching.
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0503 highspeed power enable connect
   Port 3: 0000.0503 highspeed power enable connect
   Port 4: 0000.0103 power enable connect
Hub #1 at 001:001
 INFO: individual power switching.
 WARN: Port indicators are NOT supported.
 Hub Port Status:
   Port 1: 0000.0503 highspeed power enable connect
Hub #2 at 001:003
 INFO: ganged switching.
 Hub Port Status:
   Port 1: 0000.0503 highspeed power enable connect
   Port 2: 0000.0100 power
   Port 3: 0000.0503 highspeed power enable connect
   Port 4: 0000.0100 power
   Port 5: 0000.0103 power enable connect
   Port 6: 0000.0503 highspeed power enable connect
   Port 7: 0000.0503 highspeed power enable connect
Hub #3 at 001:006
 INFO: ganged switching.
 WARN: Port indicators are NOT supported.
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0503 highspeed power enable connect
   Port 3: 0000.0103 power enable connect
   Port 4: 0000.0100 power
Hub #4 at 001:009
 INFO: individual power switching.
 Hub Port Status:
   Port 1: 0000.0000
   Port 2: 0000.0000
   Port 3: 0000.0000
   Port 4: 0000.0000
   Port 5: 0000.0000
   Port 6: 0000.0503 highspeed power enable connect
   Port 7: 0000.0503 highspeed power enable connect
Hub #5 at 001:010
 INFO: individual power switching.
 Hub Port Status:
   Port 1: 0000.0503 highspeed power enable connect
   Port 2: 0000.0503 highspeed power enable connect
   Port 3: 0000.0503 highspeed power enable connect
   Port 4: 0000.0503 highspeed power enable connect
   Port 5: 0000.0503 highspeed power enable connect
   Port 6: 0000.0503 highspeed power enable connect
   Port 7: 0000.0503 highspeed power enable connect

(Last edited by tmo26 on 24 Dec 2014, 15:22)

Forgot the most important part:

root@DIR-505-3:~# hub-ctrl -h
Usage: hub-ctrl [{-h HUBNUM | -b BUSNUM -d DEVNUM}] \
          [-P PORT] [{-p [VALUE]|-l [VALUE]}]

e.g. if you want to switch on/off power on hub #5, Port 4:

hub-ctrl -h 5 -P 4 -p 0     #switch off
hub-ctrl -h 5 -P 4 -p 1     #switch on

Which usb hub(s) are you using tmo26? I having a hard time finding a model that supports per-port power swtiching.

USB hubs which show "INFO: individual power switching." should work.
For example, the VP-H209A has this.

skvabberdivab wrote:

Which usb hub(s) are you using tmo26? I having a hard time finding a model that supports per-port power swtiching.

Yes, it's indeed hard to find such hubs, since manufacturers either do not supply any info on switching capability at all or they provide wrong information (i.e. they say individual power switching when it has only ganged switching).

I have 2xTargus, Model PAUH212; 7 port, 7 LEDs
ID 04cc:1521 ST-Ericsson USB 2.0 Hub

DeLock, Model No.: 87445; 4 port, 1 LED;
ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB

Search the net for the targus model and you'll find a page where some more hubs are listed... but don't expect too much...

I'm currently searching for a hub wit ppps and almost bought a Delock 87445. However I ended up finding a report that newer batches are missing the power switching IC's. Please see: http://www.mikrocontroller.net/topic/311841#3796012

The Delock 87445 looks to be a rebranded VP-H209A.

probono: When and where did you acquire your VP-H209A?

kylex, I got mine from Reichelt a couple of years ago, it has a Delock 87445 branding on the case indeed. But I also had success with very cheap hubs ordered from China, e.g., one Aten UH-174 that looks like http://goo.gl/HVUdNl and one entirely unlabeled one that looks like http://goo.gl/GhR1P9 - ymmv.

(Last edited by probono on 25 Jan 2015, 02:35)

Thank you. I ordered a few looking like the Aten UH-174 from different sellers and hope for the best.

Nice to see that this little helper has found it's way into the official feeds! smile


For the statistics: Some switching speeds.
Tested on DIR-505 with small bash script.

My DeLock 87445 needs approx. 35msec for one 0-1 switching cycle.
(calculated from 100x switching 1port 0-1 in 3,50sec)

Targus PAUH212 39msec for one 0-1 switching cycle
(calculated from 100x switching 7ports 0-1 in 27,31sec)

With some cheapo USB LED lights you can do nice lighteffects: Knight Rider, Strobo, ... ;-)

(Last edited by tmo26 on 26 Jan 2015, 23:40)

tmo26 wrote:

Nice to see that this little helper has found it's way into the official feeds! smile


For the statistics: Some switching speeds.
Tested on DIR-505 with small bash script.

My DeLock 87445 needs approx. 35msec for one 0-1 switching cycle.
(calculated from 100x switching 1port 0-1 in 3,50sec)

Targus PAUH212 39msec for one 0-1 switching cycle
(calculated from 100x switching 7ports 0-1 in 27,31sec)

With some cheapo USB LED lights you can do nice lighteffects: Knight Rider, Strobo, ... ;-)

Hi, tmo26
May i know your usb power control command for DIR-505?
cuz i tried hub-ctrl -b 1 -d 1 -P 1 -p 0  it shows status changing, but the power is never off.
My router is DIR-505 A1, system is CHAOS CALMER (15.05.1, r48532)
thx

Use hub-ctrl to find the hub to which your device is connected to
Use '-h HUBNUM -P PORT' instead of '-b BUSNUM -d DEVNUM'

What makes you think that the power is not turned off?
What hub (OEM + model) do you use?
Post the output of

hub-ctrl

and

lsusb
tmo26 wrote:

Use hub-ctrl to find the hub to which your device is connected to
Use '-h HUBNUM -P PORT' instead of '-b BUSNUM -d DEVNUM'

What makes you think that the power is not turned off?
What hub (OEM + model) do you use?
Post the output of

hub-ctrl

and

lsusb

Hi, tmo26
Thanks for replying, I connected a use fan on my DIR-505 router, my goal is to control the power of the usb port so i can turn on/off the fan.
i checked the port info by using hub-ctrl -v, got this info:

Hub #0 at 001:001
 INFO: individual power switching.
 WARN: Port indicators are NOT supported.
 Hub Port Status:
   Port 1: 0000.0100 power

by executing

hub-ctrl -h 0 -P 1 -p 0

the status changes to

Hub #0 at 001:001
 INFO: individual power switching.
 WARN: Port indicators are NOT supported.
 Hub Port Status:
   Port 1: 0000.0000

but the fan keeps running, never stops, could you tell me how can you control the power plz?
thanks.

Interesting result of my tryout with DIR-505 + 15.05.1:

Power Indicator = USB LED light

1) Directly connected to DIR-505 -> hub-ctrl -h 0 -P1 -p 0 has no effect, LED still on
(hub #0 = DIR-505 built in)

2) LED connected to DeLock 87445 hub; hub-ctrl -h 1 -P1 -p 0 -> LED off
(hub #1 = DIR-505 built in)
Even more interesting: After almost exactly 5min, the power comes back, without any user interaction! That's new to me....

3) LED connected to DeLock 87445 hub; hub-ctrl -h 0 -P1 -p 0 -> LED off
(hub #0 = 87445)
Contrary to 2), the LED now stays off.


-> The DIR-505 USB port does not react to hub-ctrl, althought hub-ctrl states

INFO: individual power switching

-> You need an external USB hub capable of "per port power switching" / "individual power switching".

Please mind: There are reports out there that recent versions of the DeLock 87445 do not have this capability any more

(Last edited by tmo26 on 17 Oct 2016, 18:31)

tmo26 wrote:

Interesting result of my tryout with DIR-505 + 15.05.1:

Power Indicator = USB LED light

1) Directly connected to DIR-505 -> hub-ctrl -h 0 -P1 -p 0 has no effect, LED still on
(hub #0 = DIR-505 built in)

2) LED connected to DeLock 87445 hub; hub-ctrl -h 1 -P1 -p 0 -> LED off
(hub #1 = DIR-505 built in)
Even more interesting: After almost exactly 5min, the power comes back, without any user interaction! That's new to me....

3) LED connected to DeLock 87445 hub; hub-ctrl -h 0 -P1 -p 0 -> LED off
(hub #0 = 87445)
Contrary to 2), the LED now stays off.


-> The DIR-505 USB port does not react to hub-ctrl, althought hub-ctrl states

INFO: individual power switching

-> You need an external USB hub capable of "per port power switching" / "individual power switching".

Please mind: There are reports out there that recent versions of the DeLock 87445 do not have this capability any more

Amazing, thx for your findings. aha

The discussion might have continued from here.