Syed Jahanzaib – Personal Blog to Share Knowledge !

November 22, 2012

Howto enable mikrotik to Send/Receive SMS using GSM Modem

Filed under: Mikrotik Related — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 1:25 PM

More reference can be found here.

[For Reference] Quick Script for Mikrotik Daily Info via SMS or Email !

Following is a small guide on how you can enable your mikrotik box/routerboard to send /receive SMS using GSM modem or any supported mobile set. This guide will also demonstrate that how you can enable mikrotik to receive SMS via GSM modem and execute script based on the command received in the SMS 🙂

Its very useful in many situation , for example you can configure multiple script to do various task, Few examples are that you can

  • Mikrotik Health Status,
  • create/disable users ,
  • change queues ,
  • reset router admin/user password ,
  • ask router about internet connectivity,
  • alert you if any link goes down,
  • restart router

& so much other fun things you can imagine,  another example to restart router remotely by sending SMS message to mikrotik and then it can execute the specified script, it will reboot right away. I have used this SMS function for number of tasks and it performed very well.

Hardware used for this guide

1) Mikrotik 5.20 x86 version installed on PC
2) Teltonika GSM Modem Device. (Picture attached below, you can also use any supported mobile set to do the task)

Teltonika ModemUSB/E12 UM1400

Teltonika  ModemUSB/E12 UM1400

After plugin the device into mikrotik box, reboot the mikrotik once so it can initialize the modem device.

Open Terminal and issue the following command to make view the usb port detail.

/port print

and you will see its result something like below image . . .

If you can see usb listed, it means your device have been detected.

  • Now goto TOOLS > SMS
  • Click on  ‘Receive Enabled‘ (Only if you want to enable receiving for various functions)
  • in Port, select Select USB3 (or whatever your USB port name is appearing)
  • Set the Channel to 1 [as showed in the image above]
  • In Secret type any password e.g 12345 [Secret is like your password, it is used if you want mikrotik to execute any script/command when it received appropriate sms]
  • Click APPLY

As showed in the image below . . .


Test SMS sending using Mikrotik

Now its time to send test SMS to any number using mikrotik.

  • Click on Send SMS
  • In Port, select USB3 (or whatever name of your USB is detected)
  • in Phone number, type your destination mobile number
  • in Message, type your desired message,
  • and click on SEND SMS

As showed in the image below . . .

 


Howto execute script upon receiving SMS

If you have selected ‘Receive Enabled‘, then you can receive Messages on Mikrotik in INBOX section of SMS. It can also execute any script of your choice.

For example you want to reboot your router by sending sms, use the following method.

First create appropriate script that can restart router.

/system script add name=reboot policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source="/system reboot"

Now from your own mobile , send the following sms to mikrotik connected GSM Device number.

:cmd 12345 script reboot

Explanation of above command.

  • :cmd = tell mikrotik that its the command it need to execute
  • 12345 = is the secret/password that we set in the SMS setting
  • script = it tells mikrotik that it have to execute script function
  • reboot = the script name we want mikrotik to run, which we created in above step.

You can do so much interesting stuff using this feature. I did used this option in the past to control my whole company network including Mikrotik/Linux/Microsoft Domain environment. It was used to power OFF / Power ON using WOL/ Reboot and many other functions.

I will write about them later . . .


TIPs:

Enabling receive-enabled via script

Receive Enabled turns off auto when the router reboots [it was observed in 5.x version no idea about later versions]. You can schedule a script that runs on every reboot and after 15 minutes of interval.

Below is a simple command to enable the receiving via terminal manually.

/tool sms set receive-enabled=yes

Now we will create script and add scheduler, We will use terminal to do the task quickly.

/system script add name=enable-sms-rec policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    source="/tool sms set receive-enabled=yes;"

Now add scheduler so this script runs periodically after 15 minutes each. and on start up also.

/system scheduler
add comment="execute enable-sms-rec script" disabled=no interval=15m name=\
    "execute enable-sms-rec script" on-event=enable-sms-rec policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-time=startup

Using NETWATCH tool to monitor your WAN connectivity

You can configure NETWATCH to monitor any WAN ip , for example Google dns, when it will timeout, it can can trigger script that can send sms so you can be aware about your WAN connectivity.

For example:

/tool netwatch
 add disabled=no down-script=”/sys script run down” host=8.8.8.8 \
 interval=5m timeout=1s up-script=”/sys script run up”

/system script
 add name=down policy=\
 ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
 source=”/tool sms send message=WAN_DOWN phone-number=03333021909 usb3”"
 add name=up policy=\
 ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
 source=”/tool sms send message=WAN_UP phone-number=03333021909 usb3”

Script SAMPLE:

Tto send reboot alert, when mikrotik reboots. schedule it to run on reboot.


# SENDING SMS TO ADMINS FOR RESTART ALERT
:delay 30s
:log error "Sending RESTART ALERT SMS ... by jz"

/tool sms send port=usb3 phone-number=03xxxxx message="ALERT: Mikrotik Routerboard CCR restarted now."  channel=0

Regard’s
Syed Jahanzaib

27 Comments »

  1. This Feature is Very Good For me .. I have using this feature last from 6 month .. i have created many scripts for many task .. like . new ppp user add , new hotspot user add through sms .. 😀 .. its work very good for me ..

    Like

    Comment by luckysunny88 — November 22, 2012 @ 1:33 PM

    • dear mujhy PPP user add or hotspot ma user ka script to bhej do please

      Like

      Comment by Aamir Waseem — November 26, 2012 @ 10:40 PM

    • I need add new pppoe user script 🙂
      kindly send me at mubashir.zedem[at]gmail.com

      Like

      Comment by Mubahsir Shahzad — February 26, 2015 @ 12:42 PM

  2. Dear zaib Bahi what the price Modem USB/E12 UM140 from where we can buy this device

    Like

    Comment by asif — November 22, 2012 @ 2:50 PM

  3. i tested it on different models of Nokia mobiles but no success giving error to enable receiving but sending sms is working perfectly
    [admin@MikroTik] > /tool sms set receive-enabled=yes
    ERROR

    Like

    Comment by ali — November 22, 2012 @ 5:02 PM

  4. Dear jahanzaib its really great thing which you share can we connect our mobile phone with mikrotik and can we use any old mobile like nokia will its work ? can you please tell me how we can add or remove hotspot pppoe users through sms and enable or disable our users account ? Regards

    Like

    Comment by fizzi khan — November 22, 2012 @ 7:08 PM

    • Yes create appropriate scripts to add/disable/remove and use them as described in this guide.
      I will post some examples in few days when I will get some free time.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — November 22, 2012 @ 9:57 PM

  5. zaib bhai wowwwwwwww nyc artical bhai thx bhai mujhe kuch swaal poochny thyy k keya hum isko evo main vwireless ki sim daal k use kr skty hain ya direct vwireless sy nd Userman main user ki profile or user ko add kese kiya jaasky ga sms k throw???

    Like

    Comment by Saim Ali — November 23, 2012 @ 12:21 AM

    • Yes you can do many tasks using sms, but it also depend on the script functions support.
      I have no idea about evo/vwireless I have never used them.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — November 23, 2012 @ 9:10 PM

  6. any body test this with ,mobile phone i try it but receiving is not working ?

    Like

    Comment by Bad — November 23, 2012 @ 12:55 PM

  7. how can i check my Wan side by using GSM modem … may be Netwatch option but how can it works properly … when wan link down then send a sms within a short time … ? pls help me …

    Like

    Comment by sumanctgbd — November 29, 2012 @ 3:54 PM

    • You can setup Netwatch to monitor any WAN ip , for example google dns, when it will timeout, you can triger notification
      for example:

      /tool netwatch
      add disabled=no down-script=”/sys script run down” host=8.8.8.8 \
      interval=15s timeout=1s up-script=”/sys script run up”

      /system script
      add name=down policy=\
      ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
      source=”:log info \”DOWN DOWN DOWN\””
      add name=up policy=\
      ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
      source=”:log info \”UP UP UP UP\”

      Change the script action to sms you. I have updated the article as well.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — November 29, 2012 @ 4:09 PM

  8. Thanks sir, now i have fall in another problem … i have to need scheduled on / off with ether1/ether2(both are Wan Link) … when time is 12am that time ether2 will be disable for next 12 hours … Automatically after 12 hours both Wan are active for giving internet. pls help me … how can i do the task …

    Like

    Comment by sumanctgbd — December 3, 2012 @ 8:43 AM

  9. […] Mungkin agan sudah banyak bayangan apa yg agan bisa lakuin kan?  dan kita memanfaatkan feature sms di mikrotik untuk menjalankan command pada mikrotik agan. Referensi ini saya dapat dari Syed Jahanzaib […]

    Like

    Pingback by Cara Setting Kirim / Terima SMS di MikroTik | adamonline.web.id — April 4, 2013 @ 8:16 PM

  10. pls help modem is unable to send sms it says sms sending failed sms timed out
    pls troubleshoot the samw with me on teamviwer

    Like

    Comment by mirza` — October 11, 2013 @ 1:11 PM

  11. i need to send an sms to create a user name on the hotspot, the user name and password will be specified in the sms i send to the mikrotik, kindly help,

    Like

    Comment by Kiboi — July 28, 2014 @ 4:12 AM

  12. Hi there,
    Wondering if there is a way to enable sms on lte interface? usb dongle detected as lte not usb so cant see that in ports.
    any suggestions?
    Thanks

    Like

    Comment by Farhan Razzak — March 19, 2015 @ 3:12 AM

  13. Hello Dear , Every modem is working ? i have Huwaei Modem ,can i use it ?

    Like

    Comment by Adil — August 11, 2018 @ 11:02 PM

  14. […] usefull links:https://aacable.wordpress.com/2012/11/2 … gsm-modem/http://forum.mikrotik.com/viewtopic.php … […]

    Like

    Pingback by Scripting • Re: C# API – tik4net on GitHub – Mags Forum Technology — June 12, 2019 @ 12:24 AM

  15. aoa.
    https://aacable.wordpress.com/2012/11/22/howto-enable-mikrotik-to-sendreceive-sms-using-gsm-modem/amp/

    i can not send sms alert through my android cell phone. i have been trying on different android phones and also test on zong 4g. but still not sending. settings are same with your post. i think problem between mikrotik usb port to android phone compatibility. kindly suggest me how can i do. thanks so much

    Like

    Comment by megasohaibohaib — June 29, 2019 @ 6:35 PM

  16. pls is there a way i can check my account balance using the sms thing

    Like

    Comment by Eshun Carlos — August 22, 2020 @ 12:44 PM

    • i mean i want to know my data balance. is there a script i can enter so that i can check my data balance from isp carrier.

      Like

      Comment by Eshun Carlos — August 22, 2020 @ 12:47 PM

      • ok

        On Tue, Sep 22, 2020 at 7:36 AM Syed Jahanzaib Personal Blog to Share Knowledge ! wrote:

        > Eshun Carlos commented: “i mean i want to know my data balance. is there a > script i can enter so that i can check my data balance from isp carrier.” >

        Like

        Comment by Ernest max — December 24, 2020 @ 3:35 PM


RSS feed for comments on this post. TrackBack URI

Leave a comment