Data is sent over HTTPS using Traccar's OsmAnd formatting. It seems a little data heavy to just send a small amount of information but if security isn't a concern you can use plain old HTTP and not use Apache's HTTPS proxying.
Here are LtAP and LtAP Mini scripts I have scheduled to run every 60 seconds. It formats the GPS and health data to the OsmAnd format. Traccar for some reason uses knots as the speed units. As the Mikrotik script doesn't support floats there is no way to convert km/h to knots. So even though Traccar says knots the value is km/h. Who the hell uses knots in a car anyway?
This script is best effort - if you lose comms the script will try send the message but obviously fail so your Traccar database will have gaps in time when the data couldn't be delivered.
This is for the LtAP:
Code: Select all
{
:local devid
:local spd
:local alti
:local lat
:local lon
:local vld
:local tempC
:local battdV
:local battV
:set $devid "UNIQUEDEVICEID"
:local sendurl ("https://YOUR.TRACCAR.SERVER.URL/")
/system gps monitor once do={
:set $vld $("valid")
:set $lat $("latitude")
:set $lon $("longitude")
:set $spd $("speed")
:set $alti $("altitude")
}
:set tempC [/system health get temperature]
:set battdV [/system health get voltage]
:set battV ((($battdV)/10) . "." . ($battdV % 10))
if ($vld = true) do {
:set $alti [:pick $alti 0 [:find $alti "m" -1]]
:set $spd [:pick $spd 0 [:find $spd " km/h" -1]]
:local senddata ("\?id=" . $devid. "&lat=" . $lat . "&lon=" . $lon . "&altitude=" . $alti . "&speed=" . $spd . "&battery=" . $battV . "&temperature=" . $tempC)
/tool fetch mode=https url=$sendurl port=40445 http-method=put http-data=$senddata http-header-field="Content-Type: application/x-www-form-urlencoded" output=none
}
}
This is for the LtAP Mini - there is no battery or temperature sent:
Code: Select all
{
:local devid
:local spd
:local alti
:local lat
:local lon
:local vld
:set $devid "UNIQUEDEVICEID"
:local sendurl ("https://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]]
:local senddata ("\?id=" . $devid. "&lat=" . $lat . "&lon=" . $lon . "&altitude=" . $alti . "&speed=" . $spd)
/tool fetch mode=https url=$sendurl port=40445 http-method=put http-data=$senddata http-header-field="Content-Type: application/x-www-form-urlencoded" output=none
}
}
If you use SSL this is the apache2 sites-enabled file set up for proxying HTTPS to HTTP which Traccar uses. The HTTPS OsmAnd data gets sent to port 40445 which gets mapped to HTTP 5055 (the OsmAnd port). The HTTPS web page is on port 40444 and gets mapped to HTTP 8082.
Code: Select all
<IfModule mod_ssl.c>
Listen 40444
<VirtualHost _default_:40444>
ServerName YOUR.TRACCAR.SERVER.URL
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ProxyPass /api/socket ws://localhost:8082/api/socket
ProxyPassReverse /api/socket ws://localhost:8082/api/socket
ProxyPass / http://localhost:8082/
ProxyPassReverse / http://localhost:8082/
SSLEngine on
SSLCertificateFile /etc/ssl/certs/YOURcert.pem
SSLCertificateKeyFile /etc/ssl/private/YOURpriv.pem
</VirtualHost>
Listen 40445
<VirtualHost _default_:40445>
ProxyPass / http://localhost:5055/
ProxyPassReverse / http://localhost:5055/
SSLEngine on
SSLCertificateFile /etc/ssl/certs/YOURcert.pem
SSLCertificateKeyFile /etc/ssl/private/YOURpriv.pem
</VirtualHost>