Skip to content

Latest commit

 

History

History
188 lines (146 loc) · 5.41 KB

traccar.md

File metadata and controls

188 lines (146 loc) · 5.41 KB

Traccar

Traccar is a gps tracking system. You can use it to monitor your smartphone location history


get the default traccar conf

docker run --rm --entrypoint cat debian-traccar-nginx:latest /opt/traccar/conf/traccar.xml > /run/media/ippo/TOSHIBA/traccar/conf/traccar.xml

Configuration parameters for MySQL

In traccar.xml file update the following section:

<entry key='database.driver'>com.mysql.cj.jdbc.Driver</entry>
<entry key='database.url'>jdbc:mysql://[HOST]:3306/[DATABASE]?serverTimezone=UTC&amp;allowPublicKeyRetrieval=true&amp;useSSL=false&amp;allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8&amp;sessionVariables=sql_mode=''</entry>
<entry key='database.user'>[USER]</entry>
<entry key='database.password'>[PASSWORD]</entry>
  • replace [DATABASE], [USER], [PASSWORD] with appropriate values from docker-compose.yml
  • replace [HOST] with IPv4 address from db_name section in docker network inspect

docker-compose.yml

---
services:
  traccar-db:
    image: yobasystems/alpine-mariadb
    container_name: traccar-db
    restart: unless-stopped
    command: --default-authentication-plugin=mysql_native_password
    networks:
      - trc2
    environment:
      - MYSQL_ROOT_PASSWORD=rootpassword
      - MYSQL_DATABASE=traccar-db
      - MYSQL_USER=username
      - MYSQL_PASSWORD=userpassword
    volumes:
      - ./mysql-data:/var/lib/mysql
      - ./mysql:/etc/mysql/conf.d
    ports:
      - "3306:3306"
  traccar:
    image: traccar/traccar:debian
    hostname: <server IP>
    container_name: traccar
    restart: unless-stopped
    depends_on:
      - traccar-db
    networks:
      - trc2
    ports:
      - "5055:5055"
      - "82:8082"
    volumes:
      - ./traccar.xml:/opt/traccar/conf/traccar.xml:ro
      - ./logs:/opt/traccar/logs:rw

networks:
  trc2:
    driver: bridge
    enable_ipv6: false
    ipam:
      config:
        # get the network subnet: `docker network inspect network_name`
        - subnet: 192.168.112.0/20

open root mysql shell create database, charset and priviledget user

docker exec -it traccar-db mysql -u root -p
CREATE DATABASE IF NOT EXISTS traccar-db
grant all privileges on traccar-db.* TO user'@'% identified by pass
flush privileges
ALTER DATABASE traccar CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ciALTER DATABASE traccar CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
\q

Tips & tricks

Backup traccar mysql

docker compose -f  compose-file.yml exec dbname mysqldump -uroot -pYOUR_MARIADB_ROOT_PASSWORD --all-databases > dump-$(date +%F_%H-%M-%S).sql

Restore traccar mysql

docker compose -f compose-file.yml exec -T dbname mysql -uroot -pYOUR_MARIADB_ROOT_PASSWORD < mariadb-dump.sql

Android apps

  • Android client app On client app While service is deactivated Copy the identifier, Insert the server URL (your dens,domain), Select location accuracy (high), Select frequency report ~120 sec, disable wakelock and enable the service

On status verify that the location is updating

  • Android manager app On server Top left menu Select the plus icon to add a device Select a random name And the identifier from the client app And save

The you can select the device on the top left menu

Migrate google location history takeout to traccar

download your google maps location history takeout

  • select location history only
  • and json as format
  • extract the Records.json

you'll use a python script to limit the resaults to just time , latitude and longitude converted to proper coordinates

git clone https://github.com/Scarygami/location-history-json-converter
cd location-history-json-converter
pip install -r requirements.txt
python location_history_json_converter.py Records.json  output.csv -f csv

The csv file generated by the script above will contain 3 columns:

  • time
  • latitute
  • longitude

We'll add more columns:

  • deviceid
  • protocol
  • valid

using the following command:

sed 's/^/osmand,1,/; s/$/,1/' export.csv > curated.csv

The csv file should now contain 6 columns:

  • @osmand
  • @deviceid
  • @time
  • @latitude
  • @longitude
  • @valid

These represent tc_positions table fields in traccar postgres db, so now the file should look like this:

protocol, 1, Time, Latitude, Longitude, 1
osmand, 1, 2012-08-25 21:26:20, 37.95954620, 23.72793730, 1

We are going to parse those values to as sql LOAD DATA LOCAL INFILE statement to the appropriate tc_position table fields

  • copy the csv to the container

    docker cp curated.csv traccar-db:/
  • open a root mysql shell to the db container

    docker exec -it traccar-db mysql -uroot -pROOTPASSWORD
  • connect to database

    use traccar-db
  • load the data:

    LOAD DATA LOCAL INFILE 'inn.csv' INTO TABLE tc_positions FIELDS TERMINATED BY ',' (@osmand, @deviceid,@Time,@Latitude,@Longitude,@valid) set protocol=@osmand,deviceid=@deviceid, devicetime=@Time,fixtime=@Time,servertime=@Time,latitude=@Latitude,longitude=@Longitude, valid=@valid;