Traccar SMS Gateway for None traccar use

davejh4 years ago

thanks Anton for pointing out the forum markdown

davejh4 years ago

This one works for traccar. Although you don't really need this because traccar sends the notification directly to the ip or url you specify in traccar config. I use this code along with other code to get other info from the db to send in the sms. Such as the last lat/lon entry for the device.

<?php
$json = file_get_contents('php://input');

$apikey = 'your api key';
$mobile_ip = 'http://00.000.000.00/';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $mobile_ip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{$json}");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: ' . $apikey)
);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);


davejh4 years ago

To use the above script with traccar change the api key and mobile ip values which are displayed on the sms gateway app screen:

$apikey = 'your api key';
$mobile_ip = 'http://00.000.000.00/';

Put the following in traccar.xml. All you need to change is the domain and traccar.php name which can be named anything and sett permissions to 0644

<entry key='notificator.types'>web,mail,sms</entry>
<entry key='notificator.sms.manager.class'>org.traccar.sms.HttpSmsClient</entry>
<entry key='sms.http.url'>https://yourdomain.com/traccar.php</entry>
<entry key='sms.http.template'>
    {
        "to": "{phone}",
        "message": "{message}"
    }
</entry>
</properties>

This should work well every time. I get the sms message in 2 to 3 seconds usually. And not had one message dropped. This even works if the phone where the app is installed is asleep. Make sure when you install the app that you select yes to replace the phones default sms app with the traccar sms gateway app. Awesome app

Henrique3 years ago
Error:Failed to connect to ********** port 8082: Connection refused