Community discussions

MikroTik App
 
Georgina
just joined
Topic Author
Posts: 2
Joined: Mon Oct 21, 2019 5:53 pm

Dual SIM failover

Tue Oct 22, 2019 9:15 am

Hello everyone. I'm trying to get the following scenario working on SXT LTE kit device:
1) Scheduler runs "failoverScript" every 3 minutes. If current SIM has no internet access, SIM card is switched.
2) Scheduler runs "backtomain" script every 60 minutes to check whether SIM A (main) or SIM B (backup) is in use. If SIM B is active, try switching to SIM A, ping some resource, and switch back to SIM B in case of failure. If everything works, stay on SIM A.

As I'm not experienced with Mikrotik devices and never had to deal with the scripts, I tried adapting solutions that seem to be most closely related to my needs (namely Dual SIM Application and Improved Netwatch).

The first part of my task, "failoverScript" works as intended, no problems there. However I'm struggling to get "backtomain" to work.

As there's no obvious way of debugging scripts, I added log outputs for debugging (lines 30, 32, 35 and 38 of "backtomain"). I'm only getting the log output for line 30, but nothing after that seems to work. Tested every bit individually, there should be no problems with conditions or anything, and that same bit of code works fine in another script.
Not chasing perfection here, so the code is a bit cluttered. My sole goal is to get it working as intended. Could anyone please point out what's wrong with my second script?

P.S. The IP addresses used for checking connectivity are there just as an example.
You do not have the required permissions to view the files attached to this post.
 
Georgina
just joined
Topic Author
Posts: 2
Joined: Mon Oct 21, 2019 5:53 pm

Re: Dual SIM failover  [SOLVED]

Wed Oct 23, 2019 5:50 pm

After lots of head scratching and logical thinking I realised that the error was not in the part that's strewn in debug log messages. Somehow it takes too long for the router to shut the LTE modem down after switching SIM cards and that creates some sort of race condition. Made everything working as intended by adding a slight delay after "/system routerboard sim set sim-slot=down". 1 second seemed to be enough, but I bumped it up to 3 just in case. Here's part of my "backtomain" script with the fix and no extra log messages.
# If reserve SIM is used, try switching to the main one
:if ($simSlot="up") do={
        /system routerboard sim set sim-slot=down
        :log info "Using reserve SIM, try switching to main"
        :delay 3s
# After switching to SIM A, wait for the modem to initialise
# 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
                }
 
Tim54
just joined
Posts: 2
Joined: Mon Mar 09, 2020 7:36 am

Re: Dual SIM failover

Tue Mar 17, 2020 6:05 pm

Hi, I am new to Mikrotik routers. I am wanting to write the script to my router which has been provided by you chaps but i am having difficulty on where to start. i see you cannot paste the script in the text file to the router. when I try typing it out it does not work. how do i get into the section where i can write the commands provided? currently it starts with the following: [admin@MikroTik] >

what do i need to type next befor i can retype the script for the dual sim failover?
 
Tim54
just joined
Posts: 2
Joined: Mon Mar 09, 2020 7:36 am

Re: Dual SIM failover

Sun Mar 22, 2020 10:12 am

Hi Guys,

I have the scripts which you have provided for dual sim failover and back to main sim.

I dont not know scripting at all and i am not sure what or how to enter what i require in certain areas of the script. for example:

# Wait for LTE interface to connect to mobile network for maximum "timeoutConnet" seconds - will i edit this string as follows: # Wait for LTE interface to connect to mobile network for maximum 60 seconds

another example:

:if ([/interface lte get [find name="lte1"] running]=true) do={ - [find name="lte1"] what do i put here? where and how do i name the two sim slots?

Please help, I have the two templates which has been provided by you. The failover and back to main template.

what i want to achieve is if sim A goes down, the script will switch to sim B. I do not know how many seconds or minutes to put in which will be suitable.

With the back to main script i would like it to check if sim A is up. if it is then will switch back to sim A, if it is not it will stay on sim B.

Please can anyone assist with editing the provided template scripts so i can load it directly to my mikrotik. It would be greatly appreciated as i have been struggling with this for a long time.

Regards,

Tim54
 
roe1974
Member Candidate
Member Candidate
Posts: 108
Joined: Mon Dec 31, 2018 2:14 pm

Re: Dual SIM failover

Tue Feb 16, 2021 3:26 pm

I have changed the scripts so that they also work when the APN of the two providers are different.
The following lines have to be changed in both scripts:

# Here change your values
:global providerSIMdown "HoT"
:global mainproviderSIMup "A1"
:global providerAPNdown "HoT"
:global mainproviderAPNup "A1"

providerSIMdown -> Provider name of the lower SIM card (for log)
mainproviderSIMup -> Provider name of upper SIM card (for log)
providerAPNdown -> Name of APN profile for lower SIM card
mainproviderAPNup -> name of APN profile for upper SIM card

Otherwise as described above run the "failover" script every 5min, the "backtomain" script every 60min.

Tested on LtAP, ROS 6.47.9

Best regards, Richard
You do not have the required permissions to view the files attached to this post.

Who is online

Users browsing this forum: No registered users and 15 guests