I have just set up a LtAP Mini (LTE) in place of my old TK103B gps tracker.
A friend found this thread when I mentioned I was looking into it, and your post pointed me in the right direction, so thanks!
Using GpsGate's, and MikroTik's documentation, I put together two scripts. A script to run on the LtAP, and a PHP script to convert the data.
I have the PHP script on the GpsGate server after adding PHP to IIS.
RouterOS does not play nice with decimal numbers, so converting Lat&Lon on the LtAP became a dead end for me, not for the lack of trying. Even MikroTik's documentation passes the data on to a PHP script to convert it.
IMO these are not finalised and I have work to do, but they work well enough for now.
Script to run on LtAP (I have it scheduled to run every 15 seconds)
Code: Select all
# php
:local server "domain_or_ip/gps.php"
:local port "80"
# get imei
:global lteimei
/interface lte info lte1 once do={:set $lteimei $("imei")}
# get gps data
:global datetime
:global lat
:global lon
:global alt
:global spd
:global bear
:global val
/system gps monitor once do={
:set $datetime $("date-and-time")
:set $lat $("latitude")
:set $lon $("longitude")
:set $alt $("altitude")
:set $spd $("speed")
:set $bear $("true-bearing")
:set $val $("valid")
}
# months array
:local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
# convert name of month to number
:local month ([ :find $months ([:pick $datetime 0 3]) -1 ] + 1);
:if ($month < 10) do={:set month ("0" . $month);}
# manipulate date time
:local date ([:pick $datetime 4 6] . $month . [:pick $datetime 9 11]);
:local time ([:pick $datetime 12 14] . [:pick $datetime 15 17] . [:pick $datetime 18 20]);
# send gps data to php
tool fetch mode=http url="http://$server" port=$port http-method=post \
http-data=("{ \
\"imei\":\"" . $lteimei . "\", \
\"lat\":\"" . $lat . "\", \
\"lon\":\"" . $lon . "\", \
\"alt\":\"" . $alt . "\", \
\"spd\":\"" . $spd . "\", \
\"bear\":\"" . $bear . "\", \
\"date\":\"" . $date . "\", \
\"time\":\"" . $time . "\", \
\"val\":\"" . $val . "\" \
}") \
http-content-type="application/json"
PHP script for data conversion, then passes on to Gpsgate
Code: Select all
<?php
// gpsgate server
$server = "127.0.0.1";
$port = "8008";
// Converting DMS ( Degrees / minutes / seconds ) to DMM (NMEA)
function DMStoDMM($deg,$min,$sec)
{
//return $deg+((($min*60)+($sec))/3600)
return $deg.($min+(($sec)/60));
}
function KMHtoKNOT($spd)
{
//return (($spd)/1.852)
return (($spd)/1.852);
}
// get input
$raw = file_get_contents('php://input');
$data = json_decode($raw);
// check input for all data
if (!empty($data) && is_object($data) && property_exists($data,'imei') && property_exists($data,'lat') && property_exists($data,'lon') && property_exists($data,'alt') && property_exists($data,'spd') && property_exists($data,'bear') && property_exists($data,'date') && property_exists($data,'time') && property_exists($data,'val')){
// clear variables
$imei = $lat = $lon = $alt = $spd = $bear = $date = $time = $val = '';
// set imei
$imei = $data->imei;
// the below section splits DMS coordinates apart and converts them to DMM (NMEA) format via above function
if(preg_match('/^(N|E|W|S)\ (\d+)\ (\d+)\'\ (\d+\.\d+)/',$data->lat,$result)){
$lat = DMStoDMM($result[2], $result[3], $result[4]);
$lathem = $result[1];
}
// the below section splits DMS coordinates apart and converts them to DMM (NMEA) format via above function
if(preg_match('/^(N|E|W|S)\ (\d+)\ (\d+)\'\ (\d+\.\d+)/',$data->lon,$result)){
$lon = DMStoDMM($result[2], $result[3], $result[4]);
$lonhem = $result[1];
}
// the below section splits Altitude and removes 'm'
if(preg_match('/^(\d+)\.(\d+)/',$data->alt,$result)){
$alt = $result[1].".".$result[2];
}
// the below section converts Speed to Knots via above function
if(preg_match('/^(\d+)\.(\d+)/',$data->spd,$result)){
$spd = $result[1].".".$result[2];
if(!$result[1] == "0"){
$spd = KMHtoKNOT($spd);
} else {
$spd = "0.00";
}
}
// the below section splits Bearing and removes 'deg. True'
if(preg_match('/^(\d+)\.(\d+)/',$data->bear,$result)){
$bear = $result[1].".".$result[2];
}
// set date
$date = ($data->date);
// set time
$time = ($data->time);
// the below section converts Valid to 1 (true) or 0
if(($data->val) == "true"){
$val = "1";
} else {
$val = "0";
}
// return data to source (mikrotik file gps.php), disable if not wanted
echo("IMEI: $imei\nLatitude: $lat\nLatitude Hemisphere: $lathem\nLongitude: $lon\nLongitude Hemisphere: $lonhem\nAltitude: $alt (m)\nSpeed: $spd (Knots)\nBearing: $bear (Deg.)\nDate: $date\nTime: $time\nValid: $val\ncURL: http://$server:$port/GpsGate/%3Fcmd=%24FRCMD,$imei,_SendMessage,,$lat,$lathem,$lon,$lonhem,$alt,$spd,$bear,$date,$time,$val\n\n");
$url = "http://$server:$port/GpsGate/%3Fcmd=%24FRCMD,$imei,_SendMessage,,$lat,$lathem,$lon,$lonhem,$alt,$spd,$bear,$date,$time,$val";
$ch = curl_init($url);
$result = curl_exec($ch);
curl_close($ch);
echo("$result");
}
?>
I hope this helps you, if you are still wanting to get it working.