Hi all!
I tried to send data to my traccar server with a mikrotik ltap mini device with these two codes:
{
:local devid
:local spd
:local alti
:local lat
:local lon
:local vld
:set $devid "UNIQUEDEVICEID"
:local sendurl ("http://YOUR.TRACCAR.SERVER.URL/")
/system gps monitor once do={
:set $vld $("valid")
:set $lat $("latitude")
:set $lon $("longitude")
:set $spd $("speed")
:set $alti $("altitude")
}
if ($vld = true) do {
:set $alti [:pick $alti 0 [:find $alti "m" -1]]
:set $spd [:pick $spd 0 [:find $spd " km/h" -1]]
#strip everything after the decimal
:set $spd [:pick $spd 0 [:find $spd "." -1]]
#Convert to Knots
:local speedknots (($spd * 5399 / 10000) . "." . (($spd * 5399 / 10) - ($spd * 5399 / 10000 * 1000)));
:local senddata ("\?id=" . $devid. "&lat=" . $lat . "&lon=" . $lon . "&altitude=" . $alti . "&speed=" . $spd)
/tool fetch mode=http url=$sendurl port=5055 http-method=put http-data=$senddata http-header-field="Content-Type: application/x-www-form-urlencoded" output=none
}
}
This code does not send anything at all, or nothing appears in the log
:local serverurl "SERVER";
:local serverport "5055";
:local id "IMEI";
:global Lat
:global Lon
:global Altitude
:global Bearing
:global Speed
:global Satellites
:global Valid
/system gps monitor once do={
:set $Lat $("latitude")
:set $Lon $("longitude")
:local altitudetxt $("altitude")
:set $Altitude [:pick $altitudetxt 0 5]
:local bearinval $("true-bearing")
:set $Bearing [:pick $bearinval 0 9]
:local speedtxt $("speed")
:set $Speed [:pick $speedtxt 0 8]
:set $Satellites $("satellites")
:set $Valid $("valid")
}
:local longdegree;
:set longdegree "+";
:local latdegree;
:set latdegree "+";
:set Lon ($longdegree . $Lon);
:set Lat ($latdegree . $Lat);
:global fncJD do={
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"];
:local jd
:local M [:pick $1 0 3];
:local D [:pick $1 4 6];
:local Y [:pick $1 7 11];
:for x from=0 to=([:len $months] - 1) do={
:if ([:tostr [:pick $months $x]] = $M) do={:set M ($x + 1) }
}
:if ( $M = 1 || $M = 2) do={
:set Y ($Y-1);
:set M ($M+12);
}
:local A ($Y/100)
:local B ($A/4)
:local C (2-$A+$B)
:local E ((($Y+4716) * 36525)/100)
:local F ((306001*($M+1))/10000)
:local jd ($C+$D+$E+$F-1525)
:return $jd
};
:global timestamp do={
:global fncJD $fncJD
:local currtime [/system clock get time];
:local jdnow [$fncJD [/system clock get date]]
:local days ($jdnow - 2440587)
:local ore [:pick $currtime 0 2]
:local minute [:pick $currtime 3 5]
:local secunde [:pick $currtime 6 8]
:return (($days * 86400) + ($ore * 3600) + ($minute * 60) + $secunde - [/system clock get gmt-offset]);
}
:local mystamp [$timestamp];
# :log info message="GPS Script: Posting update. lt=$Lat, lon=$Lon timestamp=$mystamp altitude=$Altitude speed=$Speed course=$Bearing satelites=$Satellites gps=$Satellites valid=$Valid";
:do {/tool fetch keep-result=no check-certificate=no url=("http://" . $serverurl . ":" . $serverport ."/\?id=$id&lat=$Lat&lon=$Lon×tamp=$mystamp&altitude=$Altitude&speed=$Speed&course=$Bearing&satelites=$Satellites&gps=$Satellites&valid=$Valid")
} on-error={:log error message="Fetch failed..."}
# :log info message="GPS Script: Posting update DONE";
And it writes errors
2024-12-10 07:33:50 INFO: [T687daedf] connected
2024-12-10 07:33:50 INFO: [T687daedf: osmand < my ip] 474554202f3f69643d383333333533303732303536383633266c61743d2b6e6f6e65266c6f6e3d2b6e6f6e65d774616d703d2d363139323031313633373326616c7469747564653d302e3030302673706565643d302e30303030303026636f757273653d38342e37323030303126736174656c697465733d30266770733d302676616c69643d66616c736520485454502f312e310d0a486f73743a203139322e3136382e312e39390d0a436f6e6e656374696f6e3a20636c6f73650d0a757365722d6167656e743a204d696b726f74696b2f372e782046657463680d0a0d0a
2024-12-10 07:33:50 WARN: [T687daedf] error - For input string: "none" - NumberFormatException (... < OsmAndProtocolDecoder:97 < ExtendedObjectDecoder:73 < ... < WrapperContext:102 < ... < WrapperInboundHandler:56 < ...)
2024-12-10 07:33:50 INFO: [T687daedf] disconnected
2024-12-10 07:33:55 INFO: [T098c9bea] connected
2024-12-10 07:33:55 INFO: [T098c9bea: osmand < my ip] 474554202f3f69643d383333333533303732303536383633266c61743d2b6e6f6e65266c6f6e3d2b6e6f6e65d774616d703d2d363139323031313633363826616c7469747564653d302e3030302673706565643d302e30303030303026636f757273653d38342e37323030303126736174656c697465733d30266770733d302676616c69643d66616c736520485454502f312e310d0a486f73743a203139322e3136382e312e39390d0a436f6e6e656374696f6e3a20636c6f73650d0a757365722d6167656e743a204d696b726f74696b2f372e782046657463680d0a0d0a
2024-12-10 07:33:55 WARN: [T098c9bea] error - For input string: "none" - NumberFormatException (... < OsmAndProtocolDecoder:97 < ExtendedObjectDecoder:73 < ... < WrapperContext:102 < ... < WrapperInboundHandler:56 < ...)
2024-12-10 07:33:55 INFO: [T098c9bea] disconnected
Pls help me!
I found the error in the second code.
This works for me:
:local serverurl "SERVER";
:local serverport "5055";
:local id "IMEI";
:global Lat
:global Lon
:global Altitude
:global Bearing
:global Speed
:global Satellites
:global Valid
/system gps monitor once do={
:set $Lat $("latitude")
:set $Lon $("longitude")
:local altitudetxt $("altitude")
:set $Altitude [:pick $altitudetxt 0 5]
:local bearinval $("true-bearing")
:set $Bearing [:pick $bearinval 0 9]
:local speedtxt $("speed")
:set $Speed [:pick $speedtxt 0 8]
:set $Satellites $("satellites")
:set $Valid $("valid")
}
:local longdegree;
:set longdegree "+";
:local latdegree;
:set latdegree "+";
:set Lon ($longdegree . $Lon);
:set Lat ($latdegree . $Lat);
:global fncJD do={
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"];
:local jd
:local M [:pick $1 0 3];
:local D [:pick $1 4 6];
:local Y [:pick $1 7 11];
:for x from=0 to=([:len $months] - 1) do={
:if ([:tostr [:pick $months $x]] = $M) do={:set M ($x + 1) }
}
:if ( $M = 1 || $M = 2) do={
:set Y ($Y-1);
:set M ($M+12);
}
:local A ($Y/100)
:local B ($A/4)
:local C (2-$A+$B)
:local E ((($Y+4716) * 36525)/100)
:local F ((306001*($M+1))/10000)
:local jd ($C+$D+$E+$F-1525)
:return $jd
};
:global timestamp do={
:global fncJD $fncJD
:local currtime [/system clock get time];
:local jdnow [$fncJD [/system clock get date]]
:local days ($jdnow - 2440587)
:local ore [:pick $currtime 0 2]
:local minute [:pick $currtime 3 5]
:local secunde [:pick $currtime 6 8]
:return (($days * 86400) + ($ore * 3600) + ($minute * 60) + $secunde - [/system clock get gmt-offset]);
}
:local mystamp [$timestamp];
# :log info message="GPS Script: Posting update. lt=$Lat, lon=$Lon timestamp=$mystamp altitude=$Altitude speed=$Speed course=$Bearing satelites=$Satellites gps=$Satellites valid=$Valid";
:do {/tool fetch keep-result=no check-certificate=no url=("http://" . $serverurl . ":" . $serverport ."/\?id=$id&lat=$Lat&lon=$Lon&tamp=$mystamp&altitude=$Altitude&speed=$Speed&course=$Bearing&satelites=$Satellites&gps=$Satellites&valid=$Valid")
} on-error={:log error message="Fetch failed..."}
# :log info message="GPS Script: Posting update DONE";
Hi all!
I tried to send data to my traccar server with a mikrotik ltap mini device with these two codes:
This code does not send anything at all, or nothing appears in the log
And it writes errors
Pls help me!