Community discussions

MikroTik App
 
warwickchapman
just joined
Topic Author
Posts: 7
Joined: Sun Jan 12, 2020 7:48 am

Battling to migrate script from v6 to v7

Thu Feb 01, 2024 10:41 am

I borrowed this script from another user and it has been working really well failing over between two SIMs.

But for the life of me, I cannot get it to work on v7. It just does nothing. I don't see any errors? What am I missing:
{
:global initTimeout 60
:global connectTimeout 60
:global minimumSignalLevel -97

:global switchSIM do={
	:local simSlot [/system routerboard modem get sim-slot]
	:if ($simSlot= "a") do={
		:log info message="Switching to \"b\" sim slot (Vodacom)"
		/interface lte set [find] apn-profile=default		
		/system routerboard modem set sim-slot=b
	} else={
		:log info message="Switching to \"a\" sim slot (MTN)"                 
		/interface lte set [find] apn-profile=default
		/system routerboard modem set sim-slot=a
	}
}

:global initialize do={
	:global initTimeout
	:local i 0
	:while ($i < $initTimeout) do={
		:if ([:len [/interface lte find ]] > 0) do={
			:return true
		}			
		:set $i ($i+1)
		:delay 1s
	}
	
	:return false
}

:global waitConnect do={
	:global connectTimeout
	:local i 0
	:while ($i < $connectTimeout) do={
		:if ([/interface lte get [find name="lte1"] running] = true) do={
			:return true
		}
		:set $i ($i+1)
		:delay 1s
	}
	:return false
}

:if ([$initialize] = true) do={
	:if ([$waitConnect] = true) do={
		:local info [/interface lte info lte1 once as-value]
		:local rssi ($info->"rssi")
#		:if ($rssi < $minimumSignalLevel) do={
#			:log info message=("Current RSSI ".$rssi." < ".$minimumSignalLevel.". Trying to switch active sim slot.")
		:if ( [/ping 8.8.8.8 count=5 size=64 interval=2s ] =0) do={
			:log error "-----No ping. Trying to switch active sim slot.";
			$switchSIM
		}
	} else={
		:log info message="GSM network is not connected. Trying to switch active sim slot."
		$switchSIM
	}
} else={
	:log info message="LTE modem did not appear, trying power-reset"
	/system routerboard usb power-reset duration=5s
}		
}

Who is online

Users browsing this forum: pav5 and 8 guests