GPS text file converter to Google Earth/Maps
From MikroTik Wiki
Before you try this, insure your setup is complete in "/tool e-mail". The "server" entry must be the "to" email address email server. The "from" entry must be a valid email address. Try a test email, then check your email. It may take several minutes to get to your mailbox.
/tool email send to=me@mydomain.com subject="Email Test" body="Email Test"
Set the gps to output data to the file gps.txt. Create an empty text file with a text editor, save as gps.kml, and upload to the router. Go to "/system script" and add the script "gps", then enter the edit source mode. Copy and paste the following code. CHANGE THE EMAIL ADDRESS near the bottom of the code. Ctrl-o to save and exit.
:global gpstext [/file get gps.txt contents];
:local longstart [:find $gpstext "longitude" -1];
:local longend [:find $gpstext "\n" $longstart];
:local latstart [:find $gpstext "latitude" -1];
:local latend [:find $gpstext "\n" $latstart];
:local validstart [:find $gpstext "valid" -1];
:local validend [:find $gpstext "\n" $validstart];
:global longitude [:pick $gpstext ($longstart + 12) $longend];
:local degreestart [:find $longitude " " -1];
:local minutestart [:find $longitude " " $degreestart];
:local secondstart [:find $longitude "'" $minutestart];
:local secondend [:find $longitude "'" $secondstart];
:local longdegree;
:local longdegreelink;
:if ([:pick $longitude 0 1] = "W") do={
:set longdegree "-";
:set longdegreelink "W";
} else={
:set longdegree "+";
:set longdegreelink "E";
};
:set longdegree ($longdegree . [:pick $longitude 2 $minutestart]);
:set longdegreelink ($longdegreelink . [:pick $longitude 2 $minutestart]);
:local longmin [:pick $longitude ($minutestart + 1) $secondstart];
:local longsec [:pick $longitude ($secondstart + 2) $secondend];
:local longfract ((([:tonum $longmin] * 6000) + ([:tonum $longsec] * 100)) / 36);
:global newlong ($longdegree . "." . $longfract);
:global newlonglink ($longdegreelink . "." . $longfract);
:global latitude [:pick $gpstext (latstart + 11) $latend];
:set degreestart [:find $latitude " " -1];
:set minutestart [:find $latitude " " $degreestart];
:set secondstart [:find $latitude "'" $minutestart];
:set secondend [:find $latitude "'" $secondstart];
:local latdegree;
:local latdegreelink;
:if ([:pick $latitude 0 1] = "N") do={
:set latdegree "+";
:set latdegreelink "N";
} else={
:set latdegree "-";
:set latdegreelink "S";
};
:set latdegree ($latdegree . [:pick $latitude 2 $minutestart]);
:set latdegreelink ($latdegreelink . [:pick $latitude 2 $minutestart]);
:local latmin [:pick $latitude ($minutestart + 1) $secondstart];
:local latsec [:pick $latitude ($secondstart + 2) $secondend];
:local latfract ((([:tonum $latmin] * 6000) + ([:tonum $latsec] * 100)) / 36);
:global newlat ($latdegree . "." . $latfract);
:global newlatlink ($latdegreelink . "." . $latfract);
:global coordinates ($newlong . "," . $newlat);
:global linkout "http://maps.google.com?q=$newlonglink$newlatlink";
:global kmlout "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<kml xmlns=\"http://www.opengis.net/kml/2.2\">
<Placemark>
<name>My router</name>
<description>My router's location</description>
<Point>
<coordinates>$coordinates</coordinates>
</Point>
</Placemark>
</kml>
";
:global oldpos;
:if ($oldpos != $coordinates) do={
/file set [/file find name=gps.kml] contents=$kmlout
/tool e-mail
send to=me@mydomain.com subject="Router move" body="Move to $linkout" file=gps.kml
:set oldpos $coordinates;
};