Skip links

Mikrotik GPS tracker

GPS Tracking with   Mikrotik routers

 

 

Script

_____________________________________________________________________

:local serverURL "https://peleng.am/server/api/api_loc.php"
:local fakeImei "XXXXXXXXXXXXXXX"  substitute your unique IMEI here
:local SIMslot "0"
:local button "0"

:global isDebug


# :put $isDebug - check current state
# :set $isDebug "terminal" - log to terminal
# :set $isDebug "off" - logging off

# Current Debug status
:set $isDebug "off"



:local gpsDateTime
:local lat
:local lon
:local alt
:local gpsSpeed
:local bearing
:local gpsValid
:local sats
:local hdop
:local DateTime
:local outputURL


#Check and set coordinate format and get data from GPS
:if ( [/system gps get coordinate-format ] != "dd") do={/system gps set coordinate-format=dd}


/system gps monitor once do={
:set $gpsDateTime $("date-and-time")
:set $lat [:pick $("latitude") 0 7]
:set $lon [:pick $("longitude") 0 8]
:set $alt $("altitude")
:set $gpsSpeed $("speed")
:set $bearing $("true-bearing")
:set $gpsValid $("valid")
:set $sats $("satellites")
:set $hdop $("horizontal-dilution")}

:set $alt [:pick $alt 0 [:find $alt "."]]
:set $gpsSpeed ([:pick $gpsSpeed 0 [:find $gpsSpeed "."]].".0")
:set $bearing ([:pick $bearing 0 [:find $bearing "."]].".0")

# Reformating date and time.
:local day [ :pick $gpsDateTime 4 6 ]
:local month [ :pick $gpsDateTime 0 3 ]
:local year [ :pick $gpsDateTime 7 11 ]
:local time [ :pick $gpsDateTime 12 19]
:local DateTime "$year-$month-$day $time"

:set $outputURL ("$serverURL?imei=$fakeImei&dt=$DateTime&lat=$lat&lng=$lon&altitude=$alt&angle=$bearing&speed=$gpsSpeed&loc_valid=1")

:if ($isDebug = "terminal") do={
:put $gpsDateTime
:put $DateTime
:put $lat
:put $lon
:put $alt
:put $gpsSpeed
:put $bearing
:put $gpsValid
:put $sats
:put $hdop
:put $serverURL
:put $fakeImei
:put $battVoltage
:put  $SIMslot
:put  $button
:put $outputURL
}

/tool fetch http-method=post url="$outputURL" output=none
____________________________________________________________________
And add our script to System->Scheduler
____________________________________________________________________
/system scheduler add interval=20s name=sched-gps on-event="/system script run send-data"
____________________________________________________________________
Do not make the interval too small, the minimum value is 10 s, 20-30 is better.
This website uses cookies to improve your web experience.