Manual:Tools/Sms
Send SMS using GSM AT commands.
It is possible to connect GSM modem to RouterOS device and use it to send SMS messages. RouterOS lists such modem as serial port that appears in '/port print' listing. GSM standard defines AT commands for sending SMS messages, and defines how messages should be encoded in these commands.
'advanced-tools' package provides command '/tool sms send' that uses standard GSM AT commands to send SMS.
Sending
/tool sms port' dst smsc=smsc message=message type=type
- port - Name of port from '/port' list that GSM modem is attached to.
- dst - Recepient phone number. Allowed characters are "0123456789*#abc". If first character is "+" then phone number type is set to 'international', otherwise it is set to 'unknown'.
- message - Message contents. It is encoded using GSM 7 encoding (UCS2 currently is not supported), so message length is limited to 160 characters (characters ^{}\[]~| are counted as two characters each). Concatenated messages and non-ASCII characters are currently not supported.
- type - If set to 'class-0', then send class 0 SMS message. It is displayed immedeately and not stored in phone.
Example
/tool sms send usb3 "20000000" message="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#\$%^&*(){}[]\"'~"
Receiving
Since v3.24 RouterOS also supports receiving of SMS messages, and can exectue scripts, and even respond to the sender.
tool sms> print reader-running: no - must turn this on to allow receiving of messages port: (unknown) - modema port (modemu can be used only by one process "/port> print" ) secret: "" - the secret password, mandatory allowed-number: "" - sender number that will be allowed to run commands, must specify with country code ie. +371XXXXXXX keep-max-sms: 0 - maximum number of keepable messages. if you set this bigger than SIM supports, new messages will not be received!
If you have enabled the reader, in /tool sms inbox> print you will see incoming messages.
Syntax
:cmd SECRET script NAME [[ VAR[=VAL] ] ... ]
- SECRET - the password
- NAME - name of the script that's available in "/system script"
- VAR - variables that will be passed to the script (can be passed as VAR or as VAR=value), separated by spaces.
Other things to remember:
- Parameters can be put into quotes "VAR"="VAL" if necessary.
- Escaping of values is not supported (VAR="\"").
- Combined SMS are not supported, every SMS will be treated separately
- 16Bit unicode messages are not supported
- SMS are decoded with the standard GSM7 alphabet, so you can't send in other encodings, otherwise it will be decoded incorrectly
Examples
Wrong:
:cmd script mans_skripts :cmd slepens script mans skripts :cmd slepens script mans_skripts var= :cmd slepens script mans_skripts var= a :cmd slepens script mans_skripts var=a a
Right:
:cmd slepens script mans_skripts :cmd slepens script "mans skripts" :cmd slepens script mans_skripts var :cmd slepens script mans_skripts var=a :cmd slepens script mans_skripts var="a a"
Debugging
/tool sms send command logs data it writes and reads. It is logged with tags gsm,debug,write and gsm,debug,read
Implementation details
This command uses "AT+CMGS" and "AT+CMGF" commands. Port is acquired for the duration of this command, and cannot be used concurently by another RouterOS component. Sending message can take a long time, this command timeouts after a minute while sending message data, and after two seconds during initial AT command exchange.