GPS Logger Binding and Owntracks - a few points from my experience

I’m transitioning from V1 bindings to V2 bindings, and have got the GPSLogger Binding to work with a Spare Phone and Owntracks. Following the bindings instruction I installed Owntracks on the iPhone and told it to connect to:

 https://MyOpenHABServer/gpstracker/owntracks

When created a new waypoint in Owntracks and I saw this in the NGINX access log:

POST /gpstracker/owntracks HTTP/1.1" 200 5 "-" "OwnTracks/13.1.7 CFNetwork/1121.2.2 Darwin/19.3.0

According to the bindings webpage

" Discovery

If the things are not defined in .things files the first time the tracker sends a GPS log record the binding recognizes it as new tracker and inserts an entry into the Inbox as new tracker with name GPS Tracker ??"

My Inbox was empty. So I put the binding into DEBUG Mode. It only gave 3 startup messages compared to the bindings webpage which lists 9. My system logged this from the binding at startup.

 2020-01-28 12:12:14.068 [DEBUG] [er.internal.GPSTrackerHandlerFactory] - Initializing callback servlets
 2020-01-28 12:12:14.083 [DEBUG] [er.internal.GPSTrackerHandlerFactory] - Started GPSTracker Callback servlet on /gpstracker/owntracks
 2020-01-28 12:12:14.086 [DEBUG] [er.internal.GPSTrackerHandlerFactory] - Started GPSTracker Callback servlet on /gpstracker/gpslogger

Eventually after many minutes and toggling all of the change options at the top of the map screen the phone sent an update that was recognised by the binding and I got these log entries

 2020-01-28 13:07:33.913 [DEBUG] [nal.provider.AbstractCallbackServlet] - Post message received from OwnTracks tracker: {"cog":93,"batt":72,"lon":174.68167891742166,"acc":50,"p":101.67362213134766,"bs":1,"vel":0,"vac":12,"lat":-36.788778319057812,"topic":"owntracks\/MyUsername\/MyDeviceID","conn":"w","tst":1580170052,"tid":"xx","_type":"location","alt":13}
 2020-01-28 13:06:31.228 [DEBUG] [nal.provider.AbstractCallbackServlet] - Post message received from OwnTracks tracker: {"_type":"waypoints","topic":"owntracks\/MyUsername\/MyDeviceID\/waypoints","waypoints":[{"_type":"waypoint","tst":1580169900,"lat":-36.791928933892002,"lon":174.68728935447001,"rad":1000,"desc":"Home2"},{"_type":"waypoint","tst":1580169706,"lat":-36.788787841797003,"lon":174.68169065209,"rad":650,"desc":"Home1"}]}
 2020-01-28 13:07:33.922 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'gpstracker:tracker:MyDevice' to inbox.
 2020-01-28 13:07:33.925 [DEBUG] [nal.provider.AbstractCallbackServlet] - There is no handler for tracker MyDevice. Check the inbox for the new tracker.

At this point I had something in my inbox I could add as a thing. I then discovered that linking the region to a switch using PaperUI didn’t seem to retain the region infomation when I queried the REST APi, so I put the item links in an item file. Testing it I discovered these entries in the log after I’d left 3 geofences and reentered one of them I saw this in the log

 2020-01-29 13:35:00.357 [DEBUG] [ofile.GPSTrackerTriggerSwitchProfile] - Trigger switch profile created for region Home1
 2020-01-29 13:35:00.359 [DEBUG] [ofile.GPSTrackerTriggerSwitchProfile] - Trigger switch profile created for region Home2
 2020-01-29 13:35:00.360 [DEBUG] [ofile.GPSTrackerTriggerSwitchProfile] - Trigger switch profile created for region Home3
 2020-01-29 13:35:00.365 [DEBUG] [ofile.GPSTrackerTriggerSwitchProfile] - Transition trigger Home3/enter handled for region Home3 by profile: ON

Suggesting that the Geofences had started updating, A quick reference to the bindings webpage found this:

Note :

  • If the binding was restarted only the second transition update will trigger event as the binding has to know the previous state.

Needing to pass in and out of a waypoint before it works after a reboot isn’t going to work for me so I’ve switched back to MQTT operation and written a rule to take care of things. The advantage of this route is all regions are updated with a location update is received from owntracks even if none of the geofence information has changed. To do this I created a mqtt thing monitoring the base topic

 owntracks/UserName/DeviceID

with 3 channels. One is a text item bound to that topic, and the other 2 are number items using JSONPATH to extract the Latitude and Longitude which I use in the distance calculation. The JSONPATH field in PaperUI reads

 *JSONPATH:lon

and

 *JSONPATH:lat

The rule is:

val PointType homeLocation = new PointType("xx.xxxxxxxxxxxxxx,yy.yyyyyyyyyyyyyyyy")
rule "Owntracks"
when Item OwntracksJSON received update then
var ot = OwntracksJSON .state.toString
if (ot.contains("Home1")){logInfo("test", "I'm inside Home1")} else {logInfo("test", "I'm outside Home1")}
//other geofence regions go in here
val PointType newLocation = new PointType(MyLatitude.state as DecimalType, MyLongitude.state as DecimalType)
var MyDistance = ((newLocation.distanceFrom(homeLocation))/1000).intValue
logInfo("test", "I am "+MyDistance +"km away")
end

I’ll keep an eye on the gpstracker bindings development and maybe give it a try when its more mature.