Dual SIM Application
Dual SIM Application
Section titled “Dual SIM Application”The Dual SIM Application enables automatic switching between SIM slots on MikroTik devices with LTE/5G modems. This functionality is essential for mobile vehicle applications where routers travel across borders and need to use different SIM cards for home and roaming networks.
Overview
Section titled “Overview”Dual SIM switching enables intelligent SIM card selection based on network conditions. Two primary use cases exist:
- Roaming-based switching: Automatically use a local SIM card when roaming is detected, switching back to the home SIM when roaming ends
- Failover-based switching: Switch to the alternative SIM when the current connection is lost
Both scripts require scheduling to run periodically, checking network conditions and performing SIM switches when necessary.
Sub-menu
Section titled “Sub-menu”The dual SIM functionality uses several RouterOS sub-menus:
/interface lte- LTE interface configuration/system routerboard sim- SIM slot management (RouterOS v6.45 and earlier)/system routerboard modem- Modem SIM slot management (RouterOS v6.45.1+)/interface lte settings- SIM slot configuration (RouterOS v7)/system script- Script execution/system scheduler- Scheduled task execution
Supported Devices
Section titled “Supported Devices”Dual SIM functionality is available on MikroTik devices with LTE modems and dual SIM slots, including:
- LtAP mini series
- LtAP series
- SXT LTE series
- wAP LTE series
- Other devices with dual SIM capability
Initial Configuration
Section titled “Initial Configuration”LTE Interface Setup
Section titled “LTE Interface Setup”Before configuring dual SIM, ensure LTE network parameters are correctly configured for each SIM card. Use the default APN profile or create separate profiles for each SIM:
/interface lte apn add apn=internet.example.com name=sim1-home/interface lte apn add apn=internet.roaming.com name=sim2-roamingFor detailed LTE setup instructions, see the LTE/5G Quick Setup Guide.
Enable Data Roaming
Section titled “Enable Data Roaming”Enable data roaming to allow connection to foreign network providers:
/interface lte set [find name=lte1] allow-roaming=yesThis setting is essential for tracking roaming status and enabling automatic SIM switching.
Configure SIM Slots
Section titled “Configure SIM Slots”Configure which SIM slots correspond to home and roaming networks. The command syntax varies by RouterOS version:
RouterOS v6.45 and earlier:
/system routerboard sim set sim-slot=downRouterOS v6.45.1+:
/system routerboard modem set sim-slot=downRouterOS v7:
/interface lte settings set sim-slot=downRoaming Script
Section titled “Roaming Script”The roaming script automatically switches SIM cards based on roaming detection. Use the home SIM when on the home network and switch to the roaming SIM when traveling abroad.
Creating the Roaming Script
Section titled “Creating the Roaming Script”Create a script named “roamingScript” in /system/script:
/system script add name=roamingScript source={# Setup and read current values:global simSlot [/system routerboard sim 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 :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=true) do={ :local Info [/interface lte monitor lte1 once as-value] :local isRoaming ($Info->"roaming") # Check which SIM slot is used :if ($simSlot="down") do={ # If "down" (home) slot, check roaming status :if ($isRoaming=true) do={ :log info message="Roaming detected, switching to SIM UP (Roaming)" /system routerboard sim set sim-slot=up } } else={ # Else "up" (roaming) slot, check roaming status :if (!$isRoaming=true) do={ :log info message="Not roaming, switching to SIM DOWN (Home)" /interface lte settings set sim-slot=down } } } 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}}Script Behavior
Section titled “Script Behavior”The roaming script performs the following actions:
- Initialization Check: Waits up to 60 seconds for the LTE interface to appear
- Connection Verification: Waits up to 60 seconds for the interface to enter “running” state
- Roaming Detection: Monitors the roaming status from LTE interface information
- SIM Switching Logic:
- If on “down” (home) slot and roaming detected → switch to “up” (roaming) slot
- If on “up” (roaming) slot and not roaming → switch to “down” (home) slot
- Failure Recovery: If LTE modem fails to initialize, performs a USB power reset
Configuration Variables
Section titled “Configuration Variables”| Variable | Description | Default |
|---|---|---|
| simSlot | Current SIM slot selection | Retrieved from system |
| timeoutLTE | Maximum wait time for LTE initialization | 60 seconds |
| timeoutConnect | Maximum wait time for network connection | 60 seconds |
Failover Script
Section titled “Failover Script”The failover script switches SIM cards when the current connection is lost, providing resilience against network outages.
Creating the Failover Script
Section titled “Creating the Failover Script”Create a script named “failoverScript” in /system/script:
/system script add name=failoverScript source={# 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 :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="down") do={ # If "down" slot, switch to up :log info message="LTE down, switching slot to UP" /interface lte settings set sim-slot=up } :if ($simSlot="up") do={ # If "up" slot, switch to down :log info message="LTE down, switching slot to DOWN" /interface lte settings set sim-slot=down } } 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}}Script Behavior
Section titled “Script Behavior”The failover script operates as follows:
- Initialization Check: Waits up to 60 seconds for the LTE interface to appear
- Connection Detection: Checks if the LTE interface is in “running” state
- SIM Switching Logic:
- If current slot is “down” and connection is down → switch to “up”
- If current slot is “up” and connection is down → switch to “down”
- Status Logging: Logs connection status changes
Scheduler Configuration
Section titled “Scheduler Configuration”Create schedulers to run the scripts periodically. A 3-minute interval is recommended to prevent overlapping executions.
Roaming Scheduler
Section titled “Roaming Scheduler”/system scheduler add interval=3m on-event=roamingScript name=RoamingFailover Scheduler
Section titled “Failover Scheduler”/system scheduler add interval=3m on-event=failoverScript name=FailoverScheduler Properties
Section titled “Scheduler Properties”| Property | Description | Default |
|---|---|---|
| interval | Time between script executions | 3m recommended |
| on-event | Script to execute | roamingScript or failoverScript |
| name | Scheduler identifier | User-defined |
| start-time | First execution time | startup |
| disabled | Enable/disable scheduler | no |
Scheduler Interval Considerations
Section titled “Scheduler Interval Considerations”| Use Case | Recommended Interval |
|---|---|
| High mobility (vehicles) | 1m - 2m |
| Standard roaming scenarios | 3m - 5m |
| Low mobility / infrequent travel | 10m - 15m |
Viewing SIM Status
Section titled “Viewing SIM Status”Check Current SIM Slot
Section titled “Check Current SIM Slot”RouterOS v6.45 and earlier:
/system routerboard sim printRouterOS v6.45.1+:
/system routerboard modem printRouterOS v7:
/interface lte settings printMonitor LTE Interface Status
Section titled “Monitor LTE Interface Status”/interface lte monitor lte1 onceOutput includes roaming status, signal strength, and connection state.
View Interface Details
Section titled “View Interface Details”/interface lte print detailTroubleshooting
Section titled “Troubleshooting”SIM Slot Change Not Taking Effect
Section titled “SIM Slot Change Not Taking Effect”- Verify RouterOS version compatibility with the command syntax
- Check that the modem supports dual SIM operation
- Review system logs for error messages
- Perform a modem power cycle manually:
/system routerboard usb power-reset duration=10sLTE Interface Not Initializing
Section titled “LTE Interface Not Initializing”- Verify LTE modem is properly installed
- Check SIM cards are correctly inserted
- Confirm antenna connections are secure
- Review LTE interface configuration:
/interface lte printExcessive Roaming Data Usage
Section titled “Excessive Roaming Data Usage”Roaming data may be consumed on the home SIM if:
- The home SIM has roaming enabled
- The script switches back and forth frequently
- Network conditions cause rapid status changes
Consider these optimizations:
- Increase scheduler interval to reduce checks
- Implement hysteresis in the roaming detection
- Use time-based restrictions for roaming SIM usage
Scripts Not Executing
Section titled “Scripts Not Executing”- Verify scripts exist in
/system/script - Check scheduler is not disabled
- Review execution logs:
/log print where message~"LTE"Modem Does Not Restart After SIM Change
Section titled “Modem Does Not Restart After SIM Change”- Verify the modem model supports hot-swap
- Check for sufficient power supply
- Review USB power-reset configuration
- Consider a hardware reboot if persistent
Best Practices
Section titled “Best Practices”Testing Before Deployment
Section titled “Testing Before Deployment”- Test SIM switching manually before automating
- Verify roaming detection works correctly
- Measure SIM switch timing on your specific device
- Test failover scenarios in a controlled environment
Production Deployment
Section titled “Production Deployment”- Use descriptive names for scripts and schedulers
- Document which slot corresponds to which SIM
- Implement monitoring for SIM switch events
- Set appropriate timeout values based on testing
- Regular review of data usage on each SIM
Data Usage Monitoring
Section titled “Data Usage Monitoring”Monitor data consumption on both SIM cards:
/interface lte monitor lte1 onceTrack usage through your mobile operator’s portal or API.
Logging Configuration
Section titled “Logging Configuration”Enable comprehensive logging for troubleshooting:
/system logging add topics=interface,lte,debugReview logs with:
/log print where message~"LTE"Related Commands
Section titled “Related Commands”/interface lte- LTE interface management/interface lte monitor- LTE connection monitoring/interface lte settings- LTE settings (v7)/system routerboard sim- SIM management (RouterOS v6.45 and earlier)/system routerboard modem- Modem management (RouterOS v6.45.1+)/system routerboard usb- USB power management/system script- Script management/system scheduler- Task scheduling