Turn off/on USB port based on schedule

I have a Beryl GL-MT1300 and need to power off and on the USB based on a schedule. It seems that the 4g modem that I have connected to it needs an actual reboot every so often and this is at a remote location (so I can't just unplug it to reset it). Is there a script or something that I can do in Luci to accomplish this using cron?

I forgot to note the uptime on the Beryl before I rebooted it. That may have given me a clue about the modem having issues because maybe a reboot caused it but I'm not thinking that was the case.

I tried a reboot of the router (Beryl). Then a disconnect/reconnect of the tether device (4g modem). Neither of those actions allowed the 4g modem to connect again. The only thing that worked was physically disconnecting the 4g modem for about a minute and then plugging it back in. This is why I am asking about power off/on for the USB port.

Firmware is 4.3.19
Reboot (router) schedule is set to off (until I know for sure that it won't affect the 4g modem).

This may or may not work for you. [OpenWrt Wiki] Turning USB power on and off

Keep looking on openwrt.org for guides.

1 Like

Thanks, I'll try that out with another GL.Inet router that I purchased for testing. It's an Opal and so fairly cheap but it may be able to help me debug and try it out.

Looks like this does not work on my device.

#changing directories and checking to see what is there
root@GL-A1300:/sys/class/leds# cd /sys/class/gpio/
root@GL-A1300:/sys/class/gpio# ls
export gpiochip412 unexport usb_power

#checking to see if the state of a pin
root@GL-A1300:/sys/class/gpio# cat /sys/class/gpio/gpio8/value
cat: can't open '/sys/class/gpio/gpio8/value': No such file or directory

#trying to create based on link you provided
root@GL-A1300:~# echo 8 > /sys/class/gpio/export
ash: write error: Invalid argument

#tried to see what usb_power might do
root@GL-A1300:/sys/class/gpio# /sys/class/gpio/usb_power
-ash: /sys/class/gpio/usb_power: Permission denied

I found this and it seems to work. MT-3000 AX: Disable USB port permanently for security reasons

#turn USB off
echo 0 > /sys/class/gpio/usb_power/value

#turn USB on
echo 1 > /sys/class/gpio/usb_power/value

Im glad you figured it out. :+1:

1 Like

It seems to work from the Slate to turn it off. I'm not so sure about the turn back on part (still need to do more testing).

Same commands are not found on the Beryl though and so if I can ever get this working then maybe I'm just switching routers.

@bruce, this is an iteresting feature, even because the router cannot hibernate the USB Port, so it's always on heating the Flash Drive.

It's also interesting to disable the flash drive when I'm sleeping. If there is no user online, there is no reason to keep the USB Port powered on.

Not sure I would do that with the flash drive. Says it might corrupt the data if you don't unmount it properly.

It's not going to kill a flash drive while it's plugged in to a USB port as it doesn't get hot enough. Ive had a flash drive plugged in to a router for over 5 yeas and still works.

1 Like

Where would I find an official response from gl.Inet for this information?

Hello,

The hardware design of the USB interface of each device may be different.
We d like to check to see if the MT1300 supports disabling and enabling USB. Please await.

1 Like

Update:

Sorry, the MT1300 does not support the USB turn off/on, as the hardware design of USB power is not controlled by the CPU GPIO.

Thank you for the response. Are there any gl.Inet routers that support this?

but I suppose if part of the schedule process had an unmount before turning power off then it would at least not potentially cause issues with a USB drive.

Sorry, GL firmware does not support this feature for the time being.

MT3000 is verified.

Is there more to add on this? Iā€™m now stuck having to drive out to a remote site because the USB 4g modem connected to my router has likely stopped responding again. Would be great if I could just schedule a power on/off recycle of the port on a weekly or daily schedule. As it is, the device has been offline for 17 hours now. Grrr

Any help on a more resilient solution would be greatly appreciated. Thanks

Given that you have a task schedule to control the LED's on/off state, WiFi Power, it might be interesting to implement a similar schedule for the USB ports too.

Maybe this switch can be an intermediate solution: DELOCK 11828.
Using this switch you can turn off the power of an USB-device by WLAN.

If possible, can you set a task schedule to restart the router, such as 2 am every day?

If the router is restarted, it will also cause the USB port to be powered off and restarted.