SMS gateway from Mikrotik with LTE interface

SMS is becoming less and less used as a means of communication these days. However, it has become a very popular tool for identification and two-factor authentication. If you have a large volume of outgoing messages, a dedicated gateway with a single SIM card won’t cut it. However, for personal use, you can use your own SIM card with a cheap SMS package. I’ll show you how to do this as easily as possible, using a Mikrotik with LTE and a minimal web server with PHP support.

I already have a Mikrotik LTaP mini kit, which provides me with a backup channel, so I only needed to purchase an SMS package. And no, sending SMS doesn’t interfere with my SIM card’s data connection. ;)

The first thing you’ll need is a PHP class for working with the Routeros API. You can get it here .
We drop the class into the required directory on the web server and create a sending script nearby.

vi sendtest.php

 <pre class="wp-block-syntaxhighlighter-code"><?php

require('routeros_api.class.php');

$API = new RouterosAPI();

$API->debug = false;

if ($API->connect('адрес_роутера', 'логин_для_mikrotik', 'пароль')) {

   $ARRAY = $API->comm("/tool/sms/send", array(
		"message"=> "Test message",
		"phone-number" => "+99899XXXXXXX",
		
   ));
	
   print_r($ARRAY);

   $API->disconnect();
}

?></pre> 

On the router side, you need to enable access to the API.

I use an API without SSL because my router and web server are on a private network and are not accessible from the outside. If you’re working over the Internet, you need to encrypt the connection.

Let’s create a group and user for the API with a minimum set of permissions
Everything’s ready! You can test it. All that’s left is to edit the sending script to suit your needs. If your script accepts a phone number as an argument, I recommend limiting the number format to a local mask unless you want to end up with a huge bill for international and toll-free numbers…