My current script is below. I would like to add something to check for an active internet connection and failover if the connection is inactive.
There also seems to be some issues with this current script around the last 2 else statements.
Can anyone assist?
Code: Select all
{
# Setup and read current values
:global simSlot [/system routerboard modem get sim-slot]
:global timeoutLTE 60
:global timeoutConnect 60
# Wait for LTE to initialize for maximum "timeoutLTE" seconds
:local i 0
:local isLTEinit false
:while ($i<$timeoutLTE) do={
:foreach n in=[/interface lte find] do={:set $isLTEinit true}
:if ($isLTEinit=true) do={
:set $i $timeoutLTE
}
:set $i ($i+1)
:delay 1s
}
# Check if LTE is initialized, or try power-reset the modem
:if ($isLTEinit=true) do={
# Wait for LTE interface to connect to mobile network for maximum "timeoutConnet" seconds
:local isConnected false
:set $i 0
:while ($i<$timeoutConnect) do={
:if ([/interface lte get [find name="lte1"] running]=true) do={
:set $isConnected true
:set $i $timeoutConnect
}
:set $i ($i+1)
:delay 1s
}
# Check if LTE is connected
if ($isConnected=false) do={
# Check which SIM slot is used
:if ($simSlot="a") do={
# If "down" slot, switch to up
:log info message="LTE down, switching slot to B"
/interface lte set [find] apn-profile=Vodacom
/system routerboard modem set sim-slot=b
}
:if ($simSlot="b") do={
# If "up" slot, switch to down
:log info message="LTE down, switching slot to A"
/interface lte set [find] apn-profile=MTN
/system routerboard modem set sim-slot=a
}
} else={
# Else "running"
:if ($isConnected=true) do={
:log info message="LTE UP"
}
}
} else={
:log info message="LTE interface did not connect to network, wait for next scheduler"
}
}
} else={
:log info message="LTE modem did not appear, trying power-reset"
/system routerboard usb power-reset duration=5s
}
}