Mobile Watchdog

[Exclusive] Mobile internet guardian program and automatically keep mobile modem alive.

When the 4G/5G routers connect to mobile internet via a SIM card and a mobile broadband modem, the internet connection can sometimes fail or get stuck. The exclusive "Mobile (WAN) Watchdog" program is designed to monitor the internet connection to improve reliability continuously.

This Mobile Watchdog works by periodically pinging a public DNS server like 8.8.8.8. As long as the ping succeeds, the script does nothing. But if the ping fails after multiple retries, indicating the mobile connection has dropped, the script will automatically reset and reconnect the mobile modem.

Once the modem disconnects and reconnects, it will automatically re-establish a new mobile broadband connection, acquiring a new IP address from the cell network.

This automated monitoring and resetting keeps the mobile internet connection alive even if it hangs or drops for some reason. Implementing a simple script like this provides robust and reliable internet uptime on 4G/5G routers with a mobile broadband modem.

The Mobile Watchdog program can be configured through the web interface under "Services > WAN Watchdog." Below is a screenshot showing its configuration options:

The Mobile Watchdog can easily be tuned for reliability against different mobile networks and troubleshooting connectivity issues. The on-demand configuration reload makes adjusting settings simple during testing or changes to the mobile infrastructure.

Restart Modem

The mobile watchdog has default settings to monitor connectivity by pinging a public IP address and restarting the mobile modem when ping failures are detected.

Enable / Disable

The watchdog can be enabled or disabled here. Turn the mobile watchdog script on or off completely. It is enabled by default.

Ping IP

Some mobile carriers may block continuous pings to specific hosts, so if the default ping target stops working, you can change it to alternate public DNS or IP addresses that are more reliable on the given mobile network.

Save & Apply Remember to click "Save & Apply" to make them active after changing settings. The watchdog script will immediately start using the new configuration without rebooting the router.

Reboot Mode

In addition to monitoring connectivity and resetting the modem, the watchdog can be configured to periodically reboot the entire router if the mobile connection remains down for a specified period.

This Periodic Reboot setting provides additional automation to recover from network issues. If a modem reset does not restore connectivity, rebooting the router hardware entirely may fix problems caused by software hangs or resource starvation.

The Reboot Mode settings allow customizing the router recovery behavior when connectivity is lost:

Diagnosis Times

This specifies the number of failed monitoring cycles before the router is rebooted. The watchdog pings the target IP 8 times per cycle. So if this is set to 5, the router will reboot after 5 cycles of 8 failed pings occur in a row.

Reboot Times

This sets the maximum number of reboots to attempt. Even if connectivity has not recovered, the watchdog will stop rebooting the router after this many attempts to avoid an endless loop.

Reboot Counts

This shows the number of router reboots triggered by the watchdog so far. It is a running count that increments each time connectivity loss causes a reboot to be triggered based on the Diagnosis Times setting.

These provide more advanced control to determine when an issue has persisted too long and requires a router reboot instead of just recycling the modem interface. The Reboot Times count prevents endless rebooting if the connectivity failure cannot be restored. The current Reboot Counts indicate how many watchdog-triggered restarts have occurred on the router.

DEV

After opening the watchdog file, we can change the advanced operation and intervals.

mobile_watchdog() {
        device=$(uci -q get network.$intf.device)
        interface=$(uci -q get watchdog.global.intf)
        failure_loss=5
        failure_loss_reset=10
        linkup=0
        failure_interval=2
        recovery_interval=10
        usbreset_interval=20
        interval=10
        sleep_time=$interval

Operation Process

When the Mobile modem has an internet connection, the Watchdog pins in every 10 seconds. After the first Ping failure, the frequency of pinging changes to once every 2 seconds. If there are 5 consecutive failures, it will trigger a reconnect action for the MOBILE connection using 'ifup.' If there are 5 consecutive failures again, it will perform a mobile modem reset.

  • failure_loss=5 - The threshold for unsuccessful pings, defaulting to taking the 'ifup' action after '5' consecutive failures.

  • failure_loss_reset=10 - The threshold for unsuccessful pings, defaulting to resetting the Mobile Modem after '10' consecutive failures.

  • failure_interval=2 - The interval for initiating another ping after a previous failure, defaulting to '2' seconds.

  • recovery_interval=10 - The time interval for initiating another ping after executing the 'ifup' action, defaulting to '10' seconds.

  • usbreset_interval=20 - The time interval for initiating another ping after resetting the Modem, defaulting to '20' seconds.

  • interval=10 - The interval for regular (successful) ping attempts, defaulting to 10 seconds.

Change Intervals

Under certain circumstances, such as a weak or unstable mobile signal leading to an extended registration and connection time for the mobile modem, it is possible to modify the intervals to the following durations.

failure_interval=30 # Ping every 30 seconds after the first Ping has failed.
recovery_interval=60 # Ping after 60 seconds after 'ifup' the modem 
usbreset_interval=120 # Ping after 120 seconds after resetting the modem
interval=60 # Pings in every 60 seconds

Last updated