RouterOS Italia

Versione completa: [Mikrotik] GPS text file converter to Google Earth/Maps
Al momento stai visualizzando i contenuti in una versione ridotta. Visualizza la versione completa e formattata.
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. 
Codice:
/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 at the top of the code . This is the address to which the email will be sent.
Ctrl-o to save and exit.
Go to "/system schedule" and schedule the script "gps" to run at whatever interval is appropriate for your application. It sends email always if the position is not valid, and also when the position is valid and it changed from the last time the script was run.
Codice:
:local email "myuser@mydomain.com";

Codice:
:global gpstext [/file get gps.txt contents];

Codice:
:local longstart [:find $gpstext "longitude" -1];

Codice:
:local longend [:find $gpstext "\n" $longstart];

Codice:
:local latstart [:find $gpstext "latitude" -1];

Codice:
:local latend [:find $gpstext "\n" $latstart];

Codice:
:local validstart [:find $gpstext "valid" -1];

Codice:
:local validend [:find $gpstext "\n" $validstart];

Codice:
:local valid false;

Codice:
:local zeros "";


Codice:
:if ([:find $gpstext "yes" $validstart] > 0) do={:set valid true;};


Codice:
:global longitude [:pick $gpstext ($longstart + 11) $longend];

Codice:
:local degreestart [:find $longitude " " -1];

Codice:
:local minutestart [:find $longitude " " $degreestart];

Codice:
:local secondstart [:find $longitude "'" $minutestart];


Codice:
:local secondend;

Codice:
:local secfract;


Codice:
:if ([:len [:find $longitude "." 0]] < 1) do={

Codice:
   :set secondend [:find $longitude "'" $secondstart];

Codice:
   :set secfract "0";

Codice:
} else={

Codice:
   :set secondend [:find $longitude "." $secondstart];

Codice:
   :set secfract [:pick $longitude ($secondend + 1) ($secondend + 2)];

Codice:
};


Codice:
:local longdegree;

Codice:
:local longdegreelink;


Codice:
:if ([:pick $longitude 0 1] = "W") do={

Codice:
   :set longdegree "-";

Codice:
   :set longdegreelink "W";

Codice:
} else={

Codice:
   :set longdegree "+";

Codice:
   :set longdegreelink "E";

Codice:
};


Codice:
:set longdegree ($longdegree . [:pick $longitude 2 $minutestart]);

Codice:
:set longdegreelink ($longdegreelink . [:pick $longitude 2 $minutestart]);

Codice:
:local longmin [:pick $longitude ($minutestart + 1) $secondstart];

Codice:
:local longsec [:pick $longitude ($secondstart + 2) $secondend];

Codice:
:local longfract ((([:tonum $longmin] * 6000) + ([:tonum $longsec] * 100) + ([:tonum $secfract] * 10) ) / 36);


Codice:
:while (([:len $zeros] + [:len $longfract]) < 4) do={

Codice:
   :set zeros ($zeros . "0");

Codice:
};


Codice:
:global newlong ($longdegree . "." . $zeros . $longfract);

Codice:
:global newlonglink ($longdegreelink . "." . $zeros . $longfract);


Codice:
:global latitude [:pick $gpstext (latstart + 10) $latend];

Codice:
:set degreestart [:find $latitude " " -1];

Codice:
:set minutestart [:find $latitude " " $degreestart];

Codice:
:set secondstart [:find $latitude "'" $minutestart];


Codice:
:if ([:len [:find $latitude "." 0]] < 1) do={

Codice:
   :set secondend [:find $latitude "'" $secondstart];

Codice:
   :set secfract "0";

Codice:
} else={

Codice:
   :set secondend [:find $latitude "." $secondstart];

Codice:
   :set secfract [:pick $latitude ($secondend + 1) ($secondend +2)];

Codice:
};


Codice:
:local latdegree;

Codice:
:local latdegreelink;


Codice:
:if ([:pick $latitude 0 1] = "N") do={

Codice:
   :set latdegree "+";

Codice:
   :set latdegreelink "N";

Codice:
} else={

Codice:
   :set latdegree "-";

Codice:
   :set latdegreelink "S";

Codice:
};


Codice:
:set latdegree ($latdegree . [:pick $latitude 2 $minutestart]);

Codice:
:set latdegreelink ($latdegreelink . [:pick $latitude 2 $minutestart]);

Codice:
:local latmin [:pick $latitude ($minutestart + 1) $secondstart];

Codice:
:local latsec [:pick $latitude ($secondstart + 2) $secondend];

Codice:
:local latfract ((([:tonum $latmin] * 6000) + ([:tonum $latsec] * 100) +([:tonum $secfract] * 10)) / 36);


Codice:
:set zeros "";


Codice:
:while (([:len $zeros] + [:len $latfract]) < 4) do={

Codice:
   :set zeros ($zeros . "0");

Codice:
};


Codice:
:global newlat ($latdegree . "." . $zeros . $latfract);

Codice:
:global newlatlink ($latdegreelink . "." . $zeros . $latfract);


Codice:
:global coordinates ($newlong . "," . $newlat);


Codice:
:global linkout "http://maps.google.com?q=$newlatlink+$newlonglink";

Codice:
:global SMlinkout "http://www.openstreetmap.org/?lat=$newlat&lon=$newlong&zoom=8&layers=M";


Codice:
:global kmlout "<?xml version=\"1.0\" encoding=\"UTF-8\"?>

Codice:
<kml xmlns=\"http://www.opengis.net/kml/2.2\">

Codice:
 <Placemark>

Codice:
   <name>My router</name>

Codice:
   <description>My router's location</description>

Codice:
   <Point>

Codice:
     <coordinates>$coordinates</coordinates>

Codice:
   </Point>

Codice:
 </Placemark>

Codice:
</kml>

Codice:
";


Codice:
:if (valid) do={

Codice:
   :global oldpos;


Codice:
   :if ($oldpos != $coordinates) do={

Codice:
       /file set [/file find name=gps.kml] contents=$kmlout

Codice:
       /tool e-mail

Codice:
       send to=$email subject="Router move" body="Moved to $latitude $longitude\r\n$linkout\r\n$SMlinkout" file=gps.kml

Codice:
       :set oldpos $coordinates;

Codice:
    };

Codice:
} else={

Codice:
        /tool e-mail

Codice:
        send to=$email subject="Router gps position invalid" body="Router gps position invalid"

Codice:
};