Community discussions

MikroTik App
 
UpRunTech
Member Candidate
Member Candidate
Topic Author
Posts: 209
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: 10
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.
 
wesleyna
just joined
Posts: 19
Joined: Tue Dec 12, 2017 4:28 pm

Re: HOWTO: Using LtAP and LtAP Mini with Traccar

Wed May 06, 2020 5:25 pm

For those that are struggling with the knots to km/h issue with traccar, you can add the following two lines :
#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)));
This goes in after:
:set $spd [:pick $spd 0 [:find $spd " km/h" -1]]
It strips the decimal( I'm not concerned about rounding it off at this point, within 1km/h is sufficient for me) and then converts it to knots. Traccar then converts it from knots to km/h again or which ever speed you prefer on the front end.

Remember to change $spd to $speedknots on your senddata string.

Who is online

Users browsing this forum: No registered users and 5 guests