Hi all,
I recently purchased a MikroTik LtAP router and put it in my van. Idea is to use it as a portable hotspot and car tracker.
My scripting skills are very limited and this is what me and AI came up with:
# Define the log function
:global logMessage do={
:local message ($1)
:log info $message
}
# Log script start
$logMessage "Starting GPS script"
# Initialize variables for current and previous coordinates
:global lat
:global lon
:global prevLat
:global prevLon
# Fetch GPS coordinates
/system gps monitor once do={
:set $lat $"latitude"
:set $lon $"longitude"
$logMessage ("Fetched GPS coordinates: lat=" . $lat . ", lon=" . $lon)
}
# Check if lat and lon were fetched correctly
:if ([:typeof $lat] = "nothing" or [:typeof $lon] = "nothing") do={
$logMessage ("Failed to fetch GPS coordinates.")
:error "Failed to fetch GPS coordinates."
}
# Ensure previous coordinates are initialized
:if ([:typeof $prevLat] = "nothing" or [:typeof $prevLon] = "nothing") do={
:set $prevLat $lat
:set $prevLon $lon
$logMessage ("Initialized previous coordinates: prevLat=" . $prevLat . ", prevLon=" . $prevLon)
}
# Log current and previous coordinates for debugging
$logMessage ("Current coordinates: lat=" . $lat . ", lon=" . $lon)
$logMessage ("Previous coordinates: prevLat=" . $prevLat . ", prevLon=" . $prevLon)
# Calculate the change in degrees
:local deltaLat ($lat - $prevLat)
:local deltaLon ($lon - $prevLon)
# Log the changes
$logMessage ("Change in degrees: deltaLat=" . $deltaLat . ", deltaLon=" . $deltaLon)
There is some more code afterward but it breaks because the output changes from DD to DMS (if I am not mistaken)
You will, of course, need a server (you can use Google Cloud free tier) to log and display the coordinates, there is a decent tutorial here:https://www.youtube.com/watch?v=2EVXUhf4ZEU