Community discussions

MikroTik App
 
nemke
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Thu Jul 31, 2014 2:52 am

GPS http send to GpsGateServer script

Sun Jul 22, 2018 12:20 am

Hello
I manage to setup LtAP and GpsGate Server to communicate and server recive cordinate. Problem is that all work manually when I input all parametars in fetch comman
Format for Server is:
http://IPADDESS:PORT/GpsGate/?$FRCMD,IMEI,_SendMessage,,latitude,hemi,longitude,hemi,alt,speed,heading,date,time,valid
So command on MT is:
/ tool fetch mode=http url="http://192.168.88.85:8008/GpsGate/\?cmd ... 8,222518,1" keep-result=no

In this format it work with no problem. So I like to do script to TAKE needed value from MT, and put in in fetch command to automate process

Where is from MT:
IMEI - 1234567890
Latitude - N 44 50' 39.972"
Longitude - E 20 24' 35.190"
Altitude - 97.5
Speed - 0,07
Date - 210718
Time - 222512
Valid Fix - 1

I am not good in scripting to make this script :-(

So any help is needed

Thank you
 
User avatar
kinx
just joined
Posts: 13
Joined: Mon Sep 04, 2017 9:16 pm
Location: 127.0.0.1
Contact:

Re: GPS http send to GpsGateServer script

Mon Aug 06, 2018 2:19 am

Hi,

Have you already been able to make a script that works with GpsGate? I'm interested too and have bought a LtAP LTE + external GPS antenna for testing in one of our vans.
If it's working fine we'll use it for tracking our vehicles and also providing WiFi Internet through LTE for the built-in Android tablets & navigation purposes.

And when it's working great, we'll suggest it to our customers :D
 
nemke
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Thu Jul 31, 2014 2:52 am

Re: GPS http send to GpsGateServer script

Mon Aug 13, 2018 2:41 am

Yes, but work only if I put manual value on it.
I want to make script that do the jub auto, take "log" and "lat" and "speed", put value in sitax which is needed to be send to GSPGate.
If I make script and I write this value, after run command I see position on GPS Gate server
/tool fetch mode=http url="http://192.168.88.85:8008/GpsGate/\?cmd ... 22518,1*65" keep-result=no

This script work, but value for log, alt and speed need to be taken direct from ROS and put in script. That part I can't do, don't know how. Problem for me is that this value can't be taken like $[system gps get longitite]
 
danofnz
just joined
Posts: 2
Joined: Sat Oct 27, 2018 6:38 am

Re: GPS http send to GpsGateServer script

Fri Nov 02, 2018 6:21 am

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.
 
nemke
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Thu Jul 31, 2014 2:52 am

Re: GPS http send to GpsGateServer script

Thu Nov 08, 2018 12:02 am

Hey man, thank you, I am not good in scripting BUT I NEED this

First script is on LTAP run avery 15sec, and second (php) is in GPS gate server ?

How you setup GPS gate for this, any screenshot ? :-)
Did you test it, is it work good ? Can be used on more fore LtAP sending data to same GPS Gate ?
 
nemke
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Thu Jul 31, 2014 2:52 am

Re: GPS http send to GpsGateServer script

Sat Nov 10, 2018 10:47 pm

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.
Plese, send me your e-mail, for contact, if you want. I need this feature. JI have few question
my contact: nemke. petrovic @ gmail. com
 
User avatar
jspool
Member
Member
Posts: 468
Joined: Sun Oct 04, 2009 4:06 am
Location: Oregon

Re: GPS http send to GpsGateServer script

Mon Nov 12, 2018 1:22 am

Especially after releasing hardware with built in GPS like the LTAP it should be apparent that the GPS package needs some attention. Mikrotik needs to devote a couple hours to the GPS package and output the data in a usable format that does not require a middleman server to convert the Mikrotik data to an acceptable format for use with the API world.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26293
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: GPS http send to GpsGateServer script

Mon Nov 12, 2018 8:52 am

You are right. We already have this in our ToDo, and will try to make it, now that LtAP mini exists.
 
User avatar
jspool
Member
Member
Posts: 468
Joined: Sun Oct 04, 2009 4:06 am
Location: Oregon

Re: GPS http send to GpsGateServer script

Mon Nov 12, 2018 6:25 pm

You are right. We already have this in our ToDo, and will try to make it, now that LtAP mini exists.
Excellent news Normis! Supports response via email a while back was not that positive at all. Glad to hear its in the ToDo list.
 
danofnz
just joined
Posts: 2
Joined: Sat Oct 27, 2018 6:38 am

Re: GPS http send to GpsGateServer script

Mon Nov 12, 2018 11:46 pm

Hey man, thank you, I am not good in scripting BUT I NEED this

First script is on LTAP run avery 15sec, and second (php) is in GPS gate server ?

How you setup GPS gate for this, any screenshot ? :-)
Did you test it, is it work good ? Can be used on more fore LtAP sending data to same GPS Gate ?
Hi,
The reason I did not go into detail with running the PHP script within GpsGate is that by default, GpsGate uses IIS Express for it's web server, and adding PHP functionality is not easy.
I use GpsGate with full IIS (OS: Windows Server Standard 1803 (Core)), and adding PHP to IIS is well documented.

You're best option may be to run a separate web server, something like XAMPP if using Windows, and have the PHP script served there.

In the first script (LtAP), the following (below) must be updated to point to the web server serving the PHP script.
# php
:local server "domain_or_ip/gps.php"
:local port "80"

In the PHP script, the following (below) must be updated to point to the GpsGate server.
// gpsgate server
$server = "127.0.0.1";
$port = "8008";

I am actively using the LtAP in my vehicle, and it is working for me. It is not perfect, but as I said previously, it's working well enough for now.
I have seen two events where the GPS data has put me half way around the world and back in 30 seconds. I plan to review the data GpsGate has from when this happened and figure out why.
 
nemke
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Thu Jul 31, 2014 2:52 am

Re: GPS http send to GpsGateServer script

Wed Nov 14, 2018 12:51 am

Especially after releasing hardware with built in GPS like the LTAP it should be apparent that the GPS package needs some attention. Mikrotik needs to devote a couple hours to the GPS package and output the data in a usable format that does not require a middleman server to convert the Mikrotik data to an acceptable format for use with the API world.

+1000 for that
LtAP is hard to use in any GPS server (GPS Gate or GPSVox), http post format (fetch in MT) is not good "supported" in GPS world. So you are right middleman server of format/sintax modification are needed and that is problem for speed and eficient.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26293
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: GPS http send to GpsGateServer script

Wed Nov 14, 2018 2:53 pm

Please simply use the external antenna, if it works good for you. The built in antenna needs improvement, as it currently only works best if LtAP ports are facing up, and there is no LTE modem inside.
 
User avatar
jspool
Member
Member
Posts: 468
Joined: Sun Oct 04, 2009 4:06 am
Location: Oregon

Re: GPS http send to GpsGateServer script

Thu Nov 15, 2018 5:58 pm

External antenna for LtAP GPS works great. I haven't used external antennas for the LTE yet as it seems to work great with the built in antennas for the current application.
 
WirelessRudy
Forum Guru
Forum Guru
Posts: 3119
Joined: Tue Aug 08, 2006 5:54 pm
Location: Spain

Re: GPS http send to GpsGateServer script

Thu Jan 17, 2019 12:31 pm

You are right. We already have this in our ToDo, and will try to make it, now that LtAP mini exists.
Any news on this?

A nice worked out example to use the unit in a tracking plotter would be nice.
Although I have a bit of understanding of ROS is haven't got a glue how to use the LtAP mini to track my vehicle.
Don't even know where to start apart from reading the wiki which leaves me clueless....
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26293
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: GPS http send to GpsGateServer script

Thu Jan 17, 2019 2:34 pm

RouterOS can already output other coordinate formats. This topic is no longer accurate.
 
crau1000
just joined
Posts: 6
Joined: Thu Jan 31, 2019 3:52 am

Re: GPS http send to GpsGateServer script

Thu Jan 31, 2019 4:48 am

Tried the format=dd in the script but still fails. I believe the script cannot handle negative coordinates. So if you have a Long of -117.1234, the add to the db fails.. then you get good ole Null Island. Any thoughts Normis?
 
User avatar
kinx
just joined
Posts: 13
Joined: Mon Sep 04, 2017 9:16 pm
Location: 127.0.0.1
Contact:

Re: GPS http send to GpsGateServer script

Thu Aug 29, 2019 4:09 pm

Tried the format=dd in the script but still fails. I believe the script cannot handle negative coordinates. So if you have a Long of -117.1234, the add to the db fails.. then you get good ole Null Island. Any thoughts Normis?
Thumbs up for this one, and bumping this thread as I could sell LtAP mini like sandwiches in Paris. But as long as there nothing stable... I can't.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26293
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: GPS http send to GpsGateServer script

Thu Aug 29, 2019 4:17 pm

Recently we fixed negative coordinates, is the issue still there ?

Who is online

Users browsing this forum: aoravent, Ellaham and 25 guests