| 1 | = Switch SIM = |
| 2 | |
| 3 | Switch SIM ref [https://wiki.mikrotik.com/wiki/Dual_SIM_Application here] |
| 4 | {{{ |
| 5 | { |
| 6 | # Setup and read current values |
| 7 | :global simSlot [/system routerboard sim get sim-slot] |
| 8 | :global timeoutLTE 60 |
| 9 | :global timeoutConnect 60 |
| 10 | :log info message="sim slot $simSlot" |
| 11 | |
| 12 | # Wait for LTE to initialize for maximum "timeoutLTE" seconds |
| 13 | :local i 0 |
| 14 | :local isLTEinit false |
| 15 | :while ($i<$timeoutLTE) do={ |
| 16 | :foreach n in=[/interface lte find] do={:set $isLTEinit true} |
| 17 | :if ($isLTEinit=true) do={ |
| 18 | :set $i $timeoutLTE |
| 19 | } |
| 20 | :set $i ($i+1) |
| 21 | :delay 1s |
| 22 | } |
| 23 | :log info message="isLTEinit $isLTEinit" |
| 24 | # Check if LTE is initialized, or try power-reset the modem |
| 25 | :if ($isLTEinit=true) do={ |
| 26 | # Wait for LTE interface to connect to mobile network for maximum "timeoutConnet" seconds |
| 27 | :local isConnected false |
| 28 | :set $i 0 |
| 29 | :while ($i<$timeoutConnect) do={ |
| 30 | :if ([/interface lte get [find name="lte1"] running]=true) do={ |
| 31 | :set $isConnected true |
| 32 | :set $i $timeoutConnect |
| 33 | } |
| 34 | :set $i ($i+1) |
| 35 | :delay 1s |
| 36 | } |
| 37 | :log info message="isLTEconnect $isConnected" |
| 38 | # Check if LTE is connected |
| 39 | :if ($isConnected=false) do={ |
| 40 | # Check which SIM slot is used |
| 41 | :if ($simSlot="down") do={ |
| 42 | # If "down" slot, switch to up |
| 43 | :log info message="LTE down, switching slot to UP" |
| 44 | /system routerboard sim set sim-slot=up |
| 45 | } |
| 46 | :if ($simSlot="up") do={ |
| 47 | # If "up" slot, switch to down |
| 48 | :log info message="LTE down, switching slot to DOWN" |
| 49 | /system routerboard sim set sim-slot=down |
| 50 | } |
| 51 | :log info message="LTE interface did not connect to network, switch sim done wait for next schedule" |
| 52 | } else={ |
| 53 | :log info message="LTE interface UP" |
| 54 | } |
| 55 | } else={ |
| 56 | :log info message="LTE modem did not appear, trying power-reset" |
| 57 | /system routerboard usb power-reset duration=5s |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | }}} |