Geofences: question

Percy6 years ago

Anton,

question: I have a geofence configured with a calendar. I get the geofenceEnter / geofenceExit notifications correctly. But it's not obeying the schedule set on the calendar.

I set my calendar from 12pm to 5pm every Monday. I simulate a geofenceEnter / geofenceExit outside the schedule I still get the geofenceEnter / geofenceExit events.

Here what I have tried already:

  • Setting the device timezone to UTC - issue not affected
  • Changing the calendar event to a different day (setting the calendar day any day other than Monday) - this works, but is a very limited solution, as I want to be able to set a time range on any day and not get fake events on the same day.

Here is the data set on the Traccar DB from an example geofence event (so you can get a context):

Geofence Calendar start / end (ical string):

BEGIN:VCALENDAR
VERSION:2.0  PRODID:-//example.com//ical//EN
BEGIN:VEVENT
UID:nyo1@example.com
SEQUENCE:0
DTSTAMP:20180521T220430Z
DTSTART:20180501T170000Z
DTEND:20180501T220000Z
RRULE:FREQ=WEEKLY;BYDAY=MO
SUMMARY:Area 3
END:VEVENT
END:VCALENDAR

Device Position fixTime (from positions table - position that triggered this event):

fixTime: 2018-05-21 19:14:31

Event (serverTime from events table - event triggered):

type: geofenceEnter
serverTime: 2018-05-21 19:18:45

My Server Location Timezone

GMT -5

As you can see all the events are triggered after 17:00 (5pm) on which Traccar should not report any event (as it is past 5pm)

What do you think can be done to have geofences calendars obey the schedule?, and not get notifications (geofenceEnter / geofenceExit) outside the schedule?

I appreciate your time.

Anton Tananaev6 years ago

I suspect the issue is with timezone somewhere. Can you provide Traccar log file fragment for around the time of the event?

Percy6 years ago

Here is a fragment from that point in time (19:18:45):

2018-05-21 19:18:45  INFO: [2D6D0D03] id: [id-here], time: 2018-05-21 19:14:31, lat: [lat-here], lon: [lon-here], speed: 0.5, course: 13.0
2018-05-21 19:18:45  INFO: [5C98FD15] id: [id-here], time: 2018-05-21 19:14:31, lat: [lat-here], lon: [lon-here], speed: 0.5, course: 13.0
2018-05-21 19:18:45 DEBUG: [2D6D0D03: 5093 < 172.24.0.1] HEX: 5b33472a363230393432383635302a303042342a434f4e4649472c54593a6737352c554c3a3630302c53593a302c434d3a312c57543a302c48523a302c54423a322c41423a302c43533a312c50503a322c48483a312c54523a302c4d4f3a312c464c3a302c56443a302c44443a302c53443a302c58593a302c57463a302c57583a302c50483a302c52573a302c4d543a312c58443a302c584c3a302c59463a312c534d3a302c48463a302c4a583a302c574c3a302c42513a302c51513a302c444c3a302c48543a305d
2018-05-21 19:18:45 DEBUG: [5C98FD15: 5093 < 172.24.0.1] HEX: 5b33472a363230393432383635302a303042342a434f4e4649472c54593a6737352c554c3a3630302c53593a302c434d3a312c57543a302c48523a302c54423a322c41423a302c43533a312c50503a322c48483a312c54523a302c4d4f3a312c464c3a302c56443a302c44443a302c53443a302c58593a302c57463a302c57583a302c50483a302c52573a302c4d543a312c58443a302c584c3a302c59463a312c534d3a302c48463a302c4a583a302c574c3a302c42513a302c51513a302c444c3a302c48543a305d
2018-05-21 19:18:55  INFO: [5C98FD15] timed out

See anything that can trace the problem? it's a watch protocol...

Anton Tananaev6 years ago

Everything seems fine. Are you sure server timezone is GMT-5?

Percy6 years ago

I haven't set any timezone setting to the Traccar server itself as there is not timezone setting on the configuration file for this. I'm using the latest release of Traccar.

The Traccar server is indeed located on a GMT-5 location.

Percy6 years ago

I saw the pull request from Abyss777 some time ago:

https://github.com/traccar/traccar/pull/2686/files/fff8f0c792606daff151624479d9ae9dc54187d5

I'm not sure if the checkMoment() method takes into account that it matches the day (Monday) and the time (both) or just passes if one matches. There is a Filter.MATCH_ANY - I'm not sure if this is satisfied by only matching the day (Monday) and it passes the test (ignoring the time). Because it is what I'm getting in my case - I change to Tuesday (for example) and I don't get any geofenceEnter / geofenceExit events (because the day nor time matches in that case - so no event is generated).

I don't do Java, but I can see this check on the code.

Anton Tananaev6 years ago

You can easily check that. Just make sure you have more than 5 hours difference between calendar event and geofence crossing.

Percy6 years ago

Good idea Anton... I tried it, and more than 5 hours difference between the calendar event and geofence crossing doesn't trigger the geofence Enter / Exit event. So this clears that theory of matching the day alone.

So this narrows down the issue to a timezone issue, but don't know how to solve it still. Traccar uses UTC right? and the geofence calendar is in UTC as well. Unless the checkMoment() is not UTC friendly. What do you suggest?

Anton Tananaev6 years ago

My guess would be that timezone from your calendar was interpreted incorrectly for some reason. Try to make your calendar with local timezone.

abyss6 years ago
DTSTART:20180501T170000Z
DTEND:20180501T220000Z

"As you can see all the events are triggered after 17:00 (5pm) on which Traccar should not report any event (as it is past 5pm)"

It should report event only from 17:00 to 22:00 UTC

Anton Tananaev6 years ago

But that's UTC timezone ("Z"). Does calendar library take into account event timezone and local time?

abyss6 years ago

Sure.
My test "Day" calendar looks like this and it is works correctly according to timezone.

DTSTART;TZID=Asia/Yekaterinburg:20161130T070000
DTEND;TZID=Asia/Yekaterinburg:20161130T230000
Anton Tananaev6 years ago

But you have local timezone in the calendar file. What if you have different timezone in the file and on the server? Does library handle it properly?

In the original example in this thread you have event from 17:00 UTC to 22:00 UTC, which translates to 12:00 GMT-5 to 17:00 GMT-5. So the issue seems to be valid.

abyss6 years ago

Just checked it again.
My development machine is in +5 timezone
This calendar (10-18 in +5) now generates events:

DTSTART:20161130T050000Z
DTEND:20161130T130000Z

This (18 -> 10 in +5) one does not

DTSTART:20161129T130000Z
DTEND:20161130T050000Z
Anton Tananaev6 years ago

OK, so it seems like it's working as expected.