Custom Script to trigger output when WAN successfully ON

Hello,

In this case you will need to modify the suggested approach a bit.

Log into the router via SSH. The process is explained here: https://wiki.teltonika-networks.com/view/Command_Line_Interfaces#Windows

Execute command:

  • vi /etc/cellular_check.sh
  • Paste the following content:
#!/bin/sh

while true; do
    ping -I qmimux0 8.8.8.8 -s 0 -c 3 -W 2 -q >/dev/null
    ret=$?
    if [ "$ret" -eq 0 ]; then
        # If ping is successful, set output to high
        ubus call ioman.gpio.dout1 update '{"value":"1"}'
    else
        # Ping failure, mobile down, set output to low
        logger "Mobile connectivity loss"
        ubus call ioman.gpio.dout1 update '{"value":"0"}'
    fi
    sleep 10
done

  • The above script will send 3 ping packets over mobile interface to 8.8.8.8 of zero size and will wait for 2 seconds for a response. If pings succeed, mobile is considered online and output pin is set to high state. If pings fail, output is set to off. The process is repeated every 10 seconds. You can modify the frequency by adjusting the sleep value.

  • Execute command below to make the script executable:

    • chmod +x /etc/cellular_check.sh
  • Next, log into the router’s WebUI

  • Navigate to System → Maintenance → Custom scripts page

  • Add the following lines:

sleep 45
sh /etc/cellular_check.sh &

This way the script will be started at the end of the router’s boot sequence and remain running in the background among other device’s processes.

The script is basic, it does not take into consideration, whether interface qmimux0 is present at the time the script is executed, therefore I added 45 second delay to ensure the mobile connectivity gets a chance to be established. So there is room for improvement.

Best regards,