Announcement

Collapse
No announcement yet.

Traccar GPS data in Homeseer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Traccar GPS data in Homeseer

    I'm using Traccar already for some years, with different kind of GPS trackers. In the beginning I was running a script that grabbed some static data from the MySQL DB, which is filled by Traccar itself. Based on requests of other board members and comments on my blog post: https://www.rutg3r.com/gps-data-traccar-homeseer/ and improvement of my own programming skills, it is resulted in a full automated script, that grab the device data dynamically and create virtual devices from it automatically.

    More information, see blogpost: https://www.rutg3r.com/gps-data-traccar-homeseer/

    Some screenshots of what the result can be:








    DailyDistance dynamically created table:



    Features:
    • *Get columns and values data from Traccar table 'positions' and store both in seperate arrays, except the last column "Attributes"
      *Get the last column "Attributes" and add all the Keys and Values of the KVPair to seperate arrays
      *Add additional virtual devices to the arrays, to provide seperate data
      *Get data from all arays, create virtual devices and update values to Homeseer devices.
      *A switch for show distances in kilometers or miles.



    The additional virtual devices are:
    • * Google Maps
      * Google Streetview (API necessary)
      * Google Streetview API counter (regarding new Google API legislation starting June 11th 2018)
      * Moving (will track other devices for if tracker is moving)
      * Aerial distance between current car location to home
      * Aerial distance between current car location and "work".
      * Presence tracker@Home
      * Presence tracker@Work, can be used for timesheet purposes or what so ever.
      * Realtime driven distance (+ saving total daily value to database)



    Release Notes:

    Traccar version 2.05
    Script: Traccar.vb:
    • Generating Streetview images is fixed. If "UseGoogleStreetview" is set to true, the Streetview API call will be run the with the first script run as well.
    • Homeseer installation path, ip address and port are now automatically retrieved from the system for saving Streetview images (reduced the user specific data)
    • Streetview device and API call counter device will now only be created when "UseGoogleStreetview" is true.
    • DailyDistance event will be run once after the Traccar script is finished.
    • When object "Odometer" is not available, the "Totaldistance" object will be taken.
    • Added additional device "Moving". When "Motion" is not populated by the gps tracker, it wil track other devices and set "Moving" to true.


    Script: Traccar_DailyDistance.vb:
    • MySQL table "DailyDistance" wil now be created dynamically (based on all GPS tracker names and values).
    • DailyDistance event will be run once after the Traccar script is finished. This will add the DailyDistance virtual devices directly. If
    • UseMySQLDB" is set to true in DailyDistance script, the MySQL table will be created as well.
    • With first script run, the current Odometer/Totaldistance value will be stored in the "Odometer Night" device, which means that the next Traccar.vb script run, can start calculating the "Odometer Daily" right away.
    • Store API counters per gps device to DailyDistance table as well (these counters will get a reset as well at script run (end of the day).


    27-05-2018
    Traccar version 2.01
    Main changes are:
    21-05-2018
    • Virtual device ranges are now created with negative value ranges (important for handling negative coordinates)

    13-05-2018
    • Kilometers/miles switch.
    • Decimal comma/point removed. Script is working fine with decimal point only.

    27-01-2019 (version 4.2.01)
    Download: https://www.rutg3r.com/download/Traccar_4.2.01.zip
    • Query update for getting gps_ids. When a new tracker is added to the Traccar webinterface and don't have uploaded data yet, the Homeseer script was having an error. Now the query will check on "lastupdate" as well. In case "lastupdate" is empty, the tracker id will be skipped.
    • Some trackers, like the Teltonika FMB920 with firmware v03.18.16, are providing not all GPS objects in all drivingmodes. Depending on motion, a different amount of objects is available in the "attributes"column in the Positions table. When you let the script creating the devices when the less objects are available, the update value array will get 'confused' when there are more objects present with the next run. Now for every virtual device update, a check will be done if the array key is already present as virtual device. If not, the virtual device will be created dynamically, so a device update can be accomplished. In other words: when new objects are populated by the tracker, the new virtual device(s) will be created automatically with the next script run (when the object is providing data).
    • At the end of the first script run, the "Traccar_DailyDistance" script will be run as well, to create the necessary devices directly (and table will be created).
    • The "Traccar_DailyDistance.vb" script is changed to save the Root counter value back to the Root device, in case Traccar.vb have to create new virtual devices.
    Last edited by Rutger; June 10, 2018, 12:45 PM.

    #2
    I use PHLocation, which gives me a device with a URL like this as a device string value https://maps.google.com/?q=xxxx,yyyyyy for my location

    I love your devices showing the actual map (and streetview) instead of a URL. Is that easy to do ?

    Comment


      #3
      it's very easy to do:
      Used variables: latitude_data, longitude_data, google_maps

      google_maps = "<iframe width='240' height='240' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.nl/maps?q=" & latitude_data & "," & longitude_data & "&ie=UTF8&z=14&t=m&output=embed'></iframe><br />Link to <a href='http://maps.google.com/maps?q=" & latitude_data & "," & longitude_data & "' target='_blank'>location</a>"

      It will create an image of the url, and below the image, a clickable link which opens a new browser tab with the same content.

      Finally, add de variable "google_maps" to a devicestring:
      hs.setdevicestring(1234, google_maps, true)

      Comment


        #4
        This is brilliant. Works beautifully ! And how do you get the streetview picture ?

        Comment


          #5
          This is really nice. I'll have to look into that GPS unit you are using. I only found it on ebay is it available anywhere else?

          Comment


            #6
            The script is added also in the first post, but for Streetview you need an API key from Google. Be aware that Google will start billing from next month (after 20.000 call requests). When you load the script every 20 seconds, it will generate normally over more than 4000 call requests per day....so with the 20.000 limit, I've found another solution:
            In my script, I use the API key url only, when the car is on the move(speed > 0). In case the api request is done, the pictures from it will be stored on the (HS) webserver as well. When the car is not moving, the API will not be requested, which will reduce they amound of API request enormously (compared to no speed check).

            In Homeseer the saved picture is loaded all the time.

            So for Streetview, you need to use a different url format, which can be added to the devicestring in the end, which can be something like:

            variables: latitude_data, longitude_data, course_data, GoogleStreetview_API

            streetview_data = "<img width='300' height='240' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.googleapis.com/maps/api/streetview?size=240x240&location=" & latitude_data & "," & longitude_data & "&heading=" & course_data & "&pitch=-0.76&key=" & GoogleStreetview_API & "'</img><br />Link to <a href='https://maps.googleapis.com/maps/api/streetview?size=640x480&location=" & latitude_data & "," & longitude_data & "&heading=" & course_data & "&pitch=-0.76&key=" & GoogleStreetview_API & "' target='_blank'>Streetview</a>"

            Create API key project: https://console.developers.google.com/projectcreate
            Last edited by Rutger; May 23, 2018, 04:24 PM.

            Comment


              #7
              Originally posted by jeubanks View Post
              This is really nice. I'll have to look into that GPS unit you are using. I only found it on ebay is it available anywhere else?
              Another board member bought it from eBay as well, in his case the Meitrack MVT380 (the 340 is an older model and probably end of life) and it's working perfect for him, especially the dual interval parameter is a nice feature.

              Comment


                #8
                Then eBay it is then. [emoji16]
                Originally posted by Rutger View Post
                Another board member bought it from eBay as well, in his case the Meitrack MVT380 (the 340 is an older model and probably end of life) and it's working perfect for him, especially the dual interval parameter is a nice feature.
                Sent from my SAMSUNG-SM-G890A using Tapatalk

                Comment


                  #9
                  May-21 11:20:22 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Traccar.vb: Variable 'streetview_local' hides a variable in an enclosing block.
                  May-21 11:20:22 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Traccar.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

                  ----------

                  Cannot fix this problem and my head hurts now!
                  Last edited by deanrparry; May 23, 2018, 03:50 PM. Reason: FIXED: found an error in the script with the help of some research on Google :) great script!

                  Comment


                    #10
                    Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Traccar.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
                    As dicussed by email, it's really strange, because this is not happening in my different systems with different Homeseer 3 versions (312 and 368)
                    Even when I'm removing the "System.Core;System.Core.dll" from the "ScriptingReferences" in settings.ini, the script continue working.

                    I'll try to reproduce this error at my system the next days.


                    Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Traccar.vb: Variable 'streetview_local' hides a variable in an enclosing block.
                    I suggest the comment line 225 completely and change line 28 to the full path. I see at my system sometimes the same issue. Declaring the full path in line 28 fixed this issue:

                    Dim streetview_local = "http://homeseer-iport/streetview.png".
                    Be aware, in your case, that the traccar folder with the icons needs its own folder....

                    Comment


                      #11
                      Think i may have resolved it by editing the script but seem to have caused another issue

                      My HomeSeer is HS3 Pro Edition 3.0.0.435 (Windows)

                      big difference in versions to you

                      Comment


                        #12
                        Please describe what is solved now and which new issues are happening now.
                        I'll install the lastest HS version this weekend in my test environment as well.

                        Comment


                          #13
                          Originally posted by Rutger View Post
                          it's very easy to do:
                          Used variables: latitude_data, longitude_data, google_maps

                          google_maps = "<iframe width='240' height='240' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='http://maps.google.nl/maps?q=" & latitude_data & "," & longitude_data & "&ie=UTF8&z=14&t=m&output=embed'></iframe><br />Link to <a href='http://maps.google.com/maps?q=" & latitude_data & "," & longitude_data & "' target='_blank'>location</a>"

                          It will create an image of the url, and below the image, a clickable link which opens a new browser tab with the same content.

                          Finally, add de variable "google_maps" to a devicestring:
                          hs.setdevicestring(1234, google_maps, true)
                          It does not show the map when logging in via myhs. Its fine when I'm logged in locally. Thats a shame but I guess there is no way to change that ?

                          .
                          Attached Files
                          Last edited by mikee123; May 24, 2018, 01:44 AM.

                          Comment


                            #14
                            Its related to MyHS I guess because their I have the same issue as yours.

                            Comment


                              #15
                              A for-loop for grabbing all definied gps trackers, and creating dynamically all virtual devices, is now working too (but not uploaded yet).
                              The name of the GPS tracker is used as prefix in the virtual devices.



                              The DailyDistance script will be edited for this change too, including assigning the icons to the virtual devices. Saving the Maps and Streetview images as well.

                              Comment

                              Working...
                              X