If WAN connection lost, restart USB WAN Device

Hi everybody,

how can i restart USB Device for WAN internet if connection is lost?
Or how can i reatart complete Lede if internet connection is lost?

I use Lede 17.01.1 in a Router TL-WR1043N/ND v4 with 4G USB Stick E353 with success.
Only few days a month, the stick lose the connection to mobile network and don’t reconnect it automatically. After a manually reboot of the router everything works again.
I am often not on site to do this manually reboot, but i need it to connect the VPN behind the router.

Thank you

Lede is the best.
Oliver

You got me at connecetion... for a 3g dongle there usually AT command to do that... maybe for 4g is is the same.
If dialing/connection parameters are properly configured you could try:

if down [4g-iface]
if up [4g-iface]

if not, you could try to unbind USB port (depending on hardware usually acts as if you unplug and replug again)

If I remember correctly:

root@OpenWrt:~# echo "usb1"> /sys/bus/usb/drivers/usb/unbind
root@OpenWrt:~# echo "usb1"> /sys/bus/usb/drivers/usb/bind

or:

opkg install usbreset
usbreset  # here you should put your vid:pid or usb kernel path

you could try to reset or rebind between if down - if up ... try a "connection keep alive" script, a continuos ping or something.

If you run reboot the connections comes up again? you could add a watchdog to reboot automatically a minute after connection lost.

I will try that.

Thank you Braian

@revilo your welcome, Remember to post later your findings here.

Hi Braian,
sure, i will do that.
But at the moment i am in trouble with a new USB Wan Stick, i bought specifically for this check.
The new Firmware of this Huawai 3372H-353 has a router inside (HiLink) which doesn't work on Lede and at the moment i try to downgrade this Firmware without success.
But this not the theme here.

What do you mean by "router" it give you private IP instead of public IP or it presents as a network device instead of a modem?
Some time ago I played with huawei usb 3g dongles and I managed to get it working as umts modem but I needed to send some string using usb-modeswitch in order to change current mode of the dongle... I also encounter problems when want to use microsd as ext root, it worked only once, long history... (it was mandatory because device has 4mb only and one USB only and wanted to avoid to use a usb hub).

see this tables about modes too as far I remember it helped me:

http://www.3g-modem-wiki.com/page/Huawei+AT-commands

Hi Braian,

sorry my late answer, but i strugled with the Huawei 3372H-353.
This LTE 4Stick act as Router on USB to LAN (Huawei HiLink) with integrated DHCP and NAT which cannot deactivated to act only as modem.
I tried to downgrade this firmware to disable the router function by a lot of ways and manuals in the internet without success.
Now it is used as a router in front of my Lede Router. I don’t like this solution because of double NAT but it works.

Thank you for your proposals to reconnect WAN.
I can’t send directly AT commands to this HiLink Router, and some USB Sticks are running into trouble with usbreset i read.
Thats why i simply use a watchdog script as you wrote, which is called by cron every 5 minutes and ping google.
If ping isn’t working i reboot complete router. This little dirty solution works with Modem and Router Sticks.
Thank you Braian

#!/bin/sh

tries=0
while [[ $tries -lt 5 ]]
do
	if /bin/ping -c 1 8.8.8.8 >/dev/null
	then
		exit 0
	fi
	tries=$((tries+1))
done

reboot

You are welcome!

Do you have knowledge on how to make kernel images?

No idea.
I just use Lede with mobile connection to create a wlan network over VPN in my faraway allotment garden, for capture live images and video streams from there, to see my garden each time in a self created electronic window at home.
:slight_smile:
Your help was appriciated for this project.
Thank you Braian

I think you have to add "-w 5" to the ping command to let the ping run into a timeout after 5s, otherwise it would wait in the line with the ping forever, since the default timeout is infinite for the ping command.

# ping --help
BusyBox v1.25.1 () multi-call binary.

Usage: ping [OPTIONS] HOST

Send ICMP ECHO_REQUEST packets to network hosts

        -4,-6           Force IP or IPv6 name resolution
        -c CNT          Send only CNT pings
        -s SIZE         Send SIZE data bytes in packets (default:56)
        -t TTL          Set TTL
        -I IFACE/IP     Use interface or IP address as source
        -W SEC          Seconds to wait for the first response (default:10)
                        (after all -c CNT packets are sent)
        -w SEC          Seconds until ping exits (default:infinite)
                        (can exit earlier with -c CNT)
        -q              Quiet, only display output at start
                        and when finished
        -p              Pattern to use for payload

thank you Michael for this hint.

It is stable at the moment but i changed the script now to:

#!/bin/sh
tries=0
while [[ $tries -lt 5 ]]
do
	if /bin/ping -c1 -w5 8.8.8.8 > /dev/null
	then
		exit 0
	fi
	tries=$((tries+1))
done
date >> /root/restarts.txt
sleep 60 && reboot

The original question was much more interesting... Resetting the interface not the device... I currently use Watchcat to reset the device, its the best I can currently do, but there is an itch in my IT brain because I know watchcat is stupid and could be better.

I currently have a 'Bridge' setup, with a WRT1200AC with the ExpressVPN firmware modified, unfortunately back on Chaos Calmer firmware. I connect to my RV park's WiFi over bgn 'radio1' wwan

Currently: The watchcat pings 1.1.1.1 every 10 seconds and on 120 seconds of failed pings resets the device... so thats 120seconds plus ~20 seconds boot time thats way too much stupid down time... I have to do 120seconds though otherwise watchcat can put me into a nasty loop if my router cant establish a connection to the VPN in time... Sooooooo

Better:
What would work so much amazingly better, that I have unfortunatly been unable to do....
When my wwan fails, or the pings dont go through, my router doesnt need a reboot, only my radio1 bgn interface... How would I set up something like watchcat to reset the interface and not my whole damn router???

Any help would be much much appreciated. Thanks!

Running wifi with no parameters will restart the wifi system with minimal effect on the rest of the router.

I have almost the same problem although in my case is worse, a reboot will not work in my case, the only thing that will work is power off and then power on. I will try the usbreset and see if that works.

it seems usbreset does not work in my case with uqmi zbt-826 mini pci-e quectel ec25-a, it does not reset it, actually it sees 2 devices and none is the mini pci-e, I gave up on it because the drop of connection was very often, I changed back to comgt and setmode lte, same speed as uqmi and no drop connection. What I liked about uqmi is that it showed the rsrq signal strength and I could do some settings on the antenna ouside, well i can still use it for antenna and changed back to comgt after the antenna is good to go. Sadly uqmi hangs for my router modem anytime and only a power off and power on would work, normal reboot does not work.

zbt 826 sees /dev/ttyUSB2 as my mini pci-e lte modem. uqmi sees my mini pci-e lte modem router as /dev/cdc-wdm0.

It's good to leave this as a reference so it can help somebody in case is having hang up problems like i did with uqmi and zbt 826 mini pci-e lte card.

Thanks for the inspiration @revilo
I've been having irregular dropouts on my LTE modem, which has required me to manually restart my interface.

I solved it by running this script in cron:

#!/bin/sh

# Test Google's DNS
tries=0
while [[ $tries -lt 5 ]]
do
	if /bin/ping -c1 -w5 8.8.8.8 > /dev/null
	then
		exit 0
	fi
	tries=$((tries+1))
done

# Test Cloudfare's DNS
tries=0
while [[ $tries -lt 5 ]]
do
        if /bin/ping -c1 -w5 1.1.1.1 > /dev/null
        then
                exit 0
        fi
        tries=$((tries+1))
done

# No contact with either provider, restart interface
ifdown wwan
sleep 5
ifup wwan
date >> /root/wwan_monitor.log

So I modified yours a bit, to inlcude a second vendor to test. Also, instead of a system reboot I just restart my wwan interface.

Running on a APU3 with Huawei ME906s LTE modem

1 Like

Pinging all over the internet to test WAN connectivity doesn't seem like a good idea.
It's best to check connectivity to the WAN gateway.

1 Like

I have also a router zbt we826 with ec25 module. The original firmware of zbt always reconnect to internet using the QMI mode. Sometimes doing a reboot to the router is not enough because you need power off the ec25 module when you are changing configurations. However I think your problem is your ISP because I tested a lot of ISP and I concluded that ISP was the problem, because I used a specific ISP and never get a disconnect event again. And yes I think comgt or usb serial works better, like my old zte usb stick.

and for my lte huawei usb stick working like a ethernet device connected to my old router mr3220, I simply use a small script to power off/on the usb port. I have used this for several years and it works. I use it each minute in the crontab

 #!/bin/bash

 if ping -q -c 1 -w 10 www.google.com >/dev/null; then
   echo "Inet is up $(date)"
 else
   echo "Inet is down $(date)"
   echo 0 > /sys/class/gpio/gpio8/value && sleep 5 && echo 1 > /sys/class/gpio/gpio8/value
 fi