In earlier posts I’ve written about different GPS trackers, and even a small preview was shown about retrieving the Traccar data into Homeseer3. In a nutshell: After a few Xexun GPS trackers and even some clones, I’ve running for almost 2,5 years the Meitrack MVT340 GPS tracker with success running in my car. A pre-paid sim-only card is inserted and it uses in my case appr 3-4 MB a month (20.000 km a year). Advantage of this MeiTrack GPS tracker is the setup for 2 time intervals. One for “ignition=ON” and the other when the “ignition=OFF”. Both intervals are configured, so during driving the gps tracker will send more frequent an update, then when the car is not used.
Cloud software was not good enough for me, or the API was not good enough to retrieve realtime data of gave data then I want to have. Mobile phone apps drained the battery too much. Therefor the Traccar GPS tracking software is now in use for several years. A lot of gps trackers are supported and documentation and support is very good. I don’t use the webinterface at all, or use the options from the webinterface, like Geofence, overspeed alarms, etc. I use only the server side for retrieving the gps data into a MySQL database. In the at the bottom of the page, I’m using my own geofences and a lot more.
Traccar configuration
In the Traccar installation folder: C:\Program Files (x86)\Traccar\conf the traccar.xml file is changed for using my own MySQL database:
Old entry:
<entry key=’database.driver’>org.h2.Driver</entry>
<entry key=’database.url’>jdbc:h2:C:\Program Files (x86)\Traccar\data\database</entry>
<entry key=’database.user’>sa</entry>
<entry key=’database.password’></entry>
New entry (login credentials are removed)
<entry key=’database.driver’>com.mysql.jdbc.Driver</entry>
<entry key=’database.url’>jdbc:mysql://localhost:3306/traccar?allowMultiQueries=true&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&sessionVariables=sql_mode=ANSI_QUOTES</entry>
<entry key=’database.user’>******</entry>
<entry key=’database.password’>******</entry>
In the section “Protocol Config”, I’ve disabled all ports for other GPS trackers (changed to comments with tags). It’s not neccessary to keep those ports open on the server, while they are not used.
<!–<entry key=’tr20.port’>5018</entry>
<entry key=’navis.port’>5019</entry>–>
<entry key=’meitrack.port’>5020</entry>
<!–<entry key=’skypatrol.port’>5021</entry>
<entry key=’gt02.port’>5022</entry>–>
Further settings are:
<entry key=’geocoder.enable’>true</entry>
<entry key=’geocoder.type’>google</entry><entry key=’web.port’>****</entry>
The web port is changed too. The Traccar software is running on my home automation server with several other web interfaces, so for this I’ve changed to port number to a free one.
MySQL database
For basic setup, installation and configuration see Traccar website.
In the end, Traccar will create all the MySQL tables like this:
For me the table “postitions” contains the most important data. Here in every row, the GPS data will be stored, for every interval:
Traccar config file
Because in the traccar.xml config file, the option for Geocode is enabled, the address is visible too, based on latitude and longitude of the current location.
In the last column “attributes” additional gps device is visible (could be different per gps device), examples are:
- Event (based on Meitrack, for example if car is moving, or ignition status is changed)
- How many satellites are connected
- How good the GPS reception is
- Odometer (total distance done with that gps tracker)
- Battery power level
- Car battery level (not in volts)
- IP address of GPS trackers
- etc
****** IMPORTANT UPDATE 13-05-2018 ******
vb.NET scripting
Compared with the previous explanation, the vb.net script is now changed the a full automated process. In the past, all the virtual devices should be created manually, which was not a nice thing to do. Even if you want to have some nice icons, it should be addedd manually to the virtual devices as well.
In every script files a “user change” section is present, which has to be changed
‘ ********** START USER CHANGE **********
‘ ********** END USER CHANGE **********
==> Changes that has to be done for “Traccar.vb”
Debug | true / false |
UseMetrics
|
true = Odometer + distances in Kilometers
false = Odometer + distances in Miles |
UseGoogleStreetview | true / false (API key necessary) |
DBserver | IP address or hostname where MySQL server is running |
DBuser | Database user for access “traccar”database |
DBpassword | Database password for access “traccar”database |
DBtraccar | Database name to access “traccar” database |
lat_home | Latitude coordinates of your home location |
lon_home | Longitude coordinates of your home location |
lat_work | Latitude coordinates of your work location |
lon_work | Longitude coordinates of your work location |
GeofenceHome | Geofence distance when “Presence Home” device would be triggered |
GeofenceWork | Geofence distance when “Presence Work” device would be triggered |
==> Changes that has to be done for “Traccar_DailyDistance.vb”
Debug | true / false |
UseMySQLDB
|
true=Create database, Update device values + Write to MySQL. The table will be updated once a day, with the driven daily distance.
false=update HS device values only |
DBserver | IP address or hostname where MySQL server is running |
DBuser | Database user for access “DailyDistance” database |
DBpassword | Database password for access “DailyDistance” database |
DBdatabase | Database name to access “DailyDistance” database |
DBtable | Table name to access “DailyDistance” database |
==> Copy the “Traccar” folder from the download to the \Homeseer 3\html\images\ folder
==> In the new script setup, the following will happen:
- Create an recurring event with name “Traccar” (The name van be anything, a name change is up to you), which will run every 20 seconds (frequency change is up to you, 20 secs is oke for me) and that will run the script “MySQL_Traccar.vb”.
- The “Traccar.vb” script will do the following:
- It will get the column names and most recent row values from Traccar table ‘positions’ and store both in seperate arrays. The last column “Attributes” will be skipped and used in a separate step.
- It will get the last column “Attributes” and add all the Keys and Values of the KVPair to seperate arrays. (Key= object name. Value= object value)
- It will add additional virtual devices to the arrays, to provide seperate data, like:
- Google Maps
- Google Streetview (API key necessary)
- Aerial distance car-home
- Aerial distance car-work
- Presence Home
- Presence Work
- It will get data from all 3 arays and create virtual devices of it. With the second run and later, only the virtual devices will be updated.
- It will create a recurring event to store and calculate the daily driven distance. It will create 2 additional virtual devices as well:
- Odometer daily (which will be updated every time the “Traccar.vb” script is running.
- Odometer night (the “Daily Distance” event will run once a day, at 23:59:05 hrs (11:59:05 PM), to store the gps odometer value. Based on this value, the daily driven distance can be calculated during the day.
- Run the event.
At the Homeseer device status homepage, you will see that all devices are created, including the additonal ones (Google Maps, etc) and at the bottom (of sorted on column “Address” 2 extra from the script “Traccar_DailyDistance” as well.
Screenshots updated on January 17, 2021 (release 4.11.0.1):
DailyDistance table layout, based on all available gps trackers including API counters when Streetview is used:
To use the two script files, two dll files has to be placed in the \bin folder of Homeseer3 (both files are provided in the download):
- MySql.Data.dll (=version 6.9.5.0)
- Newtonsoft.Json.dll (=version 7.0.1.18622)
The file “settings.ini” in folder \Config, has to be supplemented with at least (Stop Homeseer, make ini file change, Start Homeseer):
ScriptingReferences=Newtonsoft.Json;bin\Newtonsoft.Json.dll,System,MySql.Data.MySqlClient;bin\MySql.Data.dll
Release notes:
March 22, 2022 | v 4.2.13.0-1
Tested with Homeseer 4 version 4.2.13.0 on Windows 10 x64 |
Script: Traccar.vb:
Script: Traccar_DailyDistance.vb:
|
January 17, 2021 | v4.11.0.1
Tested with Traccar 4.11 and Homeseer 4.1.10.0 on Windows 8.1/10 x64 |
Script: Traccar.vb:
Script: Traccar_DailyDistance.vb:
|
15-11-2019 | v4.6.01
Tested with Traccar 4.11 and Homeseer 3.0.0.548 |
Script: Traccar.vb:
When the “Battery” value is getting lower than the value which is set in the “Battery Monitor” virtual device. the “Battery Alert” device gets triggered and the status will switch to On. ofcourse such a trigger can be done in a Homeseer Event as well. |
27-01-2019 | v4.2.01
Works only with Traccar installer 4.2. Tested with Homeseer 3.0.0.478 |
Works only when Traccar software version 4.2 is installed. Downlink link: https://www.traccar.org/download/From now on the my script versions will we follow the Traccar GPS software releases.Script: Traccar.vb:
Script: Traccar_DailyDistance.vb:
|
10-06-2018 | v2.08
Works only with Traccar installer 3.17 |
Works only when Traccar software version 3.17 is installed. Downlink link: https://www.traccar.org/download/Script: Traccar.vb:
|
06-06-2018 | v2.05 |
Script: Traccar.vb:
Script: Traccar_DailyDistance.vb:
|
29-05-2018 | v2.02 |
Script: Traccar.vb:
|
27-05-2018 | v2.01 |
Tested on Traccar release 3.17:Script: Traccar.vb:
Script: Traccar_DailyDistance.vb:
|
21-05-2018 | v1.83 |
Script: Traccar.vb:
|
19-05-2018 | v1.82 |
Script: Traccar.vb:
Script: Traccar_DailyDistance.vb:
Chart: Highcharts:
|
13-05-2018 | v1.71 |
|
Downloads:
Traccar 4.2.13.0-1.zip (378.8 KiB, 38 hits)
Traccar v41101.zip (14.1 KiB, 186 hits)
Related Posts
March 13, 2016
Store Homeseer device parameters into MySQL
February 16, 2016
Retrieve current Spotify track data into Homeseer
December 10, 2014
installing latest version
download did not include folder with grapics
or To use the two script files, two dll files has to be placed in the \bin folder of Homeseer3 (both files are provided in the download):
MySql.Data.dll (=version 6.9.5.0)
Newtonsoft.Json.dll (=version 7.0.1.18622)
The file “settings.ini” in folder \Config, has to be supplemented with at least (Stop Homeseer, make ini file change, Start Homeseer):
ScriptingReferences=Newtonsoft.Json;bin\Newtonsoft.Json.dll,System,MySql.Data.MySqlClient;bin\MySql.Data.dll
guess I need a little more help ( installing in Ubuntu 18)
Hi,
Sorry for the late response, I never received an alert to your reply, which I though I might, it maybe in spam!
Anyway I got it working, or at least further and it seemed to be a path/file conflict issue within Homeseer.
I don’t quite know why, but all the advice was to have the DLL files not in the root Hoomeseer folder, nor in the Bin folder, but actually a subfolder of Bin, this is to prevent conflicts with DLL versions already loaded into Homeseer or something like that!
Anyway, I couldn’t for the life of me get the DLL loaded using the paths you suggested in your guide, and in the end the only way to get it working was to use full filesytem paths. e.g.
ScriptingReferences=Newtonsoft.Json;”C:\Program Files (x86)\HomeSeer HS3\Bin\traccar\”Newtonsoft.Json.dll
These didn’t work for me:
ScriptingReferences=Newtonsoft.Json;Bin\Newtonsoft.Json.dll
ScriptingReferences=Newtonsoft.Json;Bin\traccar\Newtonsoft.Json.dll
Sadly I now have another issue. I am getting the following error when I try to run the traccar.vb script via event:
Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Traccar.vb: Illegal characters in path.
Any advice? I’m not sure how to debug that, I notice the traccar.vb has a debug option turned on but I don’t know how to utilise that.
Thanks
Hi,
I have just tried installing your scripts and am running into an issue with the MySQL authentication method.
When I run the traccar.vb script, the log error is:
May-31 22:55:40 Error 1 Running script C:\Program Files (x86)\HomeSeer HS3\scripts\Traccar.vb :Exception has been thrown by the target of an invocation.Object reference not set to an instance of an object.
May-31 22:55:40 Traccar Error Connecting to Database traccar: Authentication method ‘caching_sha2_password’ not supported by any of the available plugins.
Can you help ?
Thanks
Hi Dan,
I’d never such message, and nor my script users reported such error. It looks to me the issue is related to your MySQL environment. Can the script connect to any other table/database? A possible workaround is maybe visible here or it’s maybe related to the use of an older version of the “MySql.Data.dll” file?
regards,
Rutg3r
[…] my blog post “https://rutg3r.com/gps-data-traccar-homeseer/” a calculation was made in script line 139 to calculate the distance between 2 locations. […]
I have Traccar installed on my HomeSeer server but am baffled by the instructions above 🙁 it is something i am interested in but do not understand the sql part of the setup.
I suggest that we brainstorm/give support by email/HS board and post the final solution here.
Kind regards,
Rutg3r
Rutger,
In sommige gevallen laat Newtonsoft.json.dll een plugin crashen.
Een van de plugin’s is Blueirir.
Het plaatsen van de .dll in bin\scriptingipv in de homeseer root lost dit probleem vaak op.
In de settings.ini krijg je dan “ScriptingReferences=Newtonsoft.Json;C:\”your folder HS3″\Bin\scripting\Newtonsoft.Json.dll”
Zi
Newtonsoft.json;bi
Hi Patrick,
You are right, it’s related to the new Homeseer plugin setup related to this Newtonsoft.json.dll file, see https://forums.homeseer.com/showthread.php?t=189876. In my case I don’t use the Blue Iris plugin (or HS3 v3.0.0.333 or late), so for me it’s working fine till now. Because of high memory usage issues, I’m still on v3.0.0.312.