SMS
RouterOS provides SMS messaging capabilities for MikroTik devices with LTE modems. Send and receive SMS messages, execute USSD commands for carrier services, and integrate cellular notifications into your network management workflow.
Overview
Section titled “Overview”SMS functionality in RouterOS enables:
- Sending SMS - Send text messages to phone numbers
- Receiving SMS - Store and retrieve incoming messages in inbox
- USSD Commands - Execute Unstructured Supplementary Service Data for carrier services like balance checks
- Auto-respond - Configure automatic replies to incoming messages
- Script Integration - Trigger actions based on incoming SMS
Requirements
Section titled “Requirements”SMS requires:
- A MikroTik device with an LTE modem (built-in or USB)
- A SIM card with SMS capability
- RouterOS v6 or later
Sub-menu
Section titled “Sub-menu”The SMS functionality is accessed through:
/tool sms- Main SMS configuration/tool sms inbox- Received messages/tool sms outbox- Messages pending delivery/tool sms sent- Successfully sent messages/interface lte at-chat- Direct AT command interface
Configuration
Section titled “Configuration”Enabling SMS
Section titled “Enabling SMS”Enable the SMS tool and configure the LTE interface:
/tool sms set enabled=yes port=lte1View SMS settings:
/tool sms printParameters:
| Property | Description |
|---|---|
enabled | Enable or disable SMS functionality |
port | LTE interface to use (e.g., lte1) |
receive-on | Which SIM to receive messages on (sim1, sim2) |
auto-respond | Message to auto-respond with |
secret | Password to restrict SMS commands |
Configuring SIM Selection
Section titled “Configuring SIM Selection”For dual-SIM devices, specify which SIM to use:
/tool sms set port=lte1 receive-on=sim1
/tool sms set port=lte1 receive-on=sim2Sending SMS
Section titled “Sending SMS”Basic SMS Send
Section titled “Basic SMS Send”Send a simple SMS message:
/tool sms send phone-number=+1234567890 message="Hello from RouterOS"Send to a contact saved on the SIM:
/tool sms send phone-number="John Doe" message="Status check"Sending to Multiple Recipients
Section titled “Sending to Multiple Recipients”Send the same message to multiple numbers:
/tool sms send phone-number=+1234567890,0987654321 message="Network alert"Send from Script
Section titled “Send from Script”Automate SMS sending from RouterOS scripts:
/system script add name=send-alert source={ /tool sms send phone-number=+1234567890 message="Router reboot detected"}Send with Custom Sender
Section titled “Send with Custom Sender”Some carriers support custom sender IDs:
/tool sms send phone-number=+1234567890 message="Alert" from="Router-Alert"Receiving SMS
Section titled “Receiving SMS”Viewing Inbox
Section titled “Viewing Inbox”List all received messages:
/tool sms inbox printView messages from a specific phone number:
/tool sms inbox print where phone~"+1234"Inbox Properties
Section titled “Inbox Properties”| Property | Description |
|---|---|
phone | Sender’s phone number |
message | Message body |
timestamp | Time when the message was received (from operator, not router local time) |
type | Message type |
Delete Messages
Section titled “Delete Messages”Delete a specific message:
/tool sms inbox remove numbers=0Delete all messages:
/tool sms inbox remove [find]Auto-Respond
Section titled “Auto-Respond”Simple Auto-Response
Section titled “Simple Auto-Response”Configure automatic responses to incoming SMS:
/tool sms set auto-respond="Router is running. Uptime: [/system resource get uptime]"Password-Protected Commands
Section titled “Password-Protected Commands”Require a secret for SMS commands:
/tool sms set secret=MySecret123When a secret is set, only messages starting with the secret will trigger responses or scripts.
Custom Auto-Response Script
Section titled “Custom Auto-Response Script”Use a script for dynamic responses:
/system script add name=sms-response source={ :local msg [/tool sms inbox get [find] message] :local phone [/tool sms inbox get [find] phone-number]
:if ($msg = "status") do={ :local uptime [/system resource get uptime] :local cpu [/system resource get cpu-load] /tool sms send phone-number=$phone message="Uptime: $uptime, CPU: $cpu%" }}Schedule the script to check for new messages:
/system scheduler add name=check-sms interval=30s on-event=sms-responseUSSD Messages
Section titled “USSD Messages”USSD (Unstructured Supplementary Service Data) is used for carrier interactions like checking account balance, activating services, and managing prepaid accounts.
Sending USSD Commands
Section titled “Sending USSD Commands”Send a USSD command directly:
/interface lte at-chat input="*123#"Use the AT+CUSD command for explicit USSD handling:
/interface lte at-chat input="AT+CUSD=1,\"*123#\",15"Common USSD Commands
Section titled “Common USSD Commands”| Code | Service |
|---|---|
*123# | Balance check (common) |
*101# | Data balance |
*102# | Voice balance |
*121# | Active offers |
##002# | Cancel call forwarding |
USSD Response Handling
Section titled “USSD Response Handling”Capture the USSD response:
/interface lte at-chat input="AT+CUSD=1,\"*123#\",15"Response appears in the log:
/log print where message~"CUSD"USSD Script Example
Section titled “USSD Script Example”Create a script to check balance:
/system script add name=check-balance source={ :local response "" /interface lte at-chat input="AT+CUSD=1,\"*123#\",15" :delay 2 :log info "USSD balance check completed"}SMS-Triggered Actions
Section titled “SMS-Triggered Actions”Trigger Scripts with SMS
Section titled “Trigger Scripts with SMS”Execute RouterOS commands via SMS for remote management:
/tool sms set secret=AdminPass
/system script add name=sms-command source={ :local msg [/tool sms inbox get [find] message] :local phone [/tool sms inbox get [find] phone-number]
:if ($msg = "reboot") do={ /system reboot }}Remote Reboot Example
Section titled “Remote Reboot Example”- Configure SMS command handler:
/system script add name=remote-reboot source={ :local cmd [/tool sms inbox get [find] message]
:if ($cmd = "reboot") do={ :log warning "Remote reboot command received" :delay 5 /system reboot }}- Set up scheduler to check:
/system scheduler add name=sms-check interval=60s on-event=remote-rebootSignal Alert Script
Section titled “Signal Alert Script”Receive alerts when LTE signal drops below threshold:
/system script add name=signal-alert source={ :local rssi [/interface lte info [find] rssi] :if ($rssi < -95) do={ /tool sms send phone-number=+1234567890 message="Warning: LTE signal low: $rssi dBm" }}Debugging
Section titled “Debugging”Enable SMS Logging
Section titled “Enable SMS Logging”View SMS-related logs:
/log print where message~"sms\|SMS\|sms"AT Command Interface
Section titled “AT Command Interface”Send direct AT commands to the modem:
/interface lte at-chat input="AT"Check modem SMS capability:
/interface lte at-chat input="AT+CMGF?"List stored messages:
/interface lte at-chat input="AT+CMGL=\"ALL\""Common AT Commands
Section titled “Common AT Commands”| Command | Description |
|---|---|
AT | Test modem |
AT+CMGF=1 | Set text mode |
AT+CMGS="number" | Send SMS |
AT+CMGL="ALL" | List all messages |
AT+CMGD=1 | Delete message 1 |
AT+CUSD=1,"code",15 | Send USSD |
Modem Information
Section titled “Modem Information”Get modem capabilities:
/interface lte info [find] onceCheck SIM status:
/interface lte info [find] sim-statusTroubleshooting
Section titled “Troubleshooting”SMS not sending:
/interface lte at-chat input="AT+CMGS=\"+1234567890\""> Test message<ctrl+Z>
/log print where message~"error\|failed"No messages in inbox:
/interface lte at-chat input="AT+CPMS?"SIM not recognized:
/system routerboard sim resetExamples
Section titled “Examples”SMS Notification on Router Events
Section titled “SMS Notification on Router Events”Send SMS when router reboots:
/system script add name=startup-notify source={ :delay 30 /tool sms send phone-number=+1234567890 message="Router booted: $[/system identity get name]"}Add to startup:
/system scheduler add name=startup on-event=startup-notify startup-time=startupWAN Failure Alert
Section titled “WAN Failure Alert”Monitor primary WAN and alert via SMS:
/system script add name=wan-failover source={ :local pingResult [/ping 8.8.8.8 count=3] :if ($pingResult = 0) do={ /tool sms send phone-number=+1234567890 message="Primary WAN down! Checking LTE..." :delay 10 :local lteStatus [/interface lte get [find] running] :if ($lteStatus = true) do={ /tool sms send phone-number=+1234567890 message="LTE is up - failover active" } else={ /tool sms send phone-number=+1234567890 message="ALERT: Both WANs down!" } }}Schedule periodic checks:
/system scheduler add name=wan-monitor interval=5m on-event=wan-failoverTemperature Alert
Section titled “Temperature Alert”Monitor device temperature and alert:
/system script add name=temp-alert source={ :local temp [/system health get temperature] :if ($temp > 70) do={ /tool sms send phone-number=+1234567890 message="Warning: Router temperature is ${temp}C" }}Related Topics
Section titled “Related Topics”- Mobile Networking - Overview of mobile networking
- LTE/5G - LTE interface configuration
- Dual SIM Application - Multi-SIM management
- Signal Monitoring - LTE signal metrics