Community discussions

MikroTik App
 
UpRunTech
Member Candidate
Member Candidate
Topic Author
Posts: 110
Joined: Fri Jul 27, 2012 12:11 pm

HOWTO: Using LtAP and LtAP Mini with Traccar

Sat Dec 28, 2019 1:11 am

The Traccar project (www.traccar.org) is a terrific GPS tracking server and manager and perfect for pairing up with the LtAP and LtAP mini. It was pretty straightforward to set up Traccar on a Raspberry Pi 4 following the documentation on the site. I use a Let's Encrypt certificate so that all data submission from the LtAP and user interaction with the server was done using HTTPS.

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:
{
    :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:
{
    :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.
<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>
 
repcio
just joined
Posts: 2
Joined: Wed Jan 08, 2020 10:28 am

Re: HOWTO: Using LtAP and LtAP Mini with Traccar

Wed Mar 25, 2020 10:55 pm

to "force" traccar to use km/h you have to change configuration of the osmand protocol. osmand.speed variable should be kmh.
Probably this will brake Traccar Client which is sending speed in knots., arrgghhh.

Who is online

Users browsing this forum: No registered users and 2 guests