Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

location frequency control #1168

Closed
yajrendrag opened this issue Jan 18, 2022 · 8 comments
Closed

location frequency control #1168

yajrendrag opened this issue Jan 18, 2022 · 8 comments
Milestone

Comments

@yajrendrag
Copy link

yajrendrag commented Jan 18, 2022

  • App build number: 2.4.6
  • Android version: 12
  • Device: Samsung S20+5G
  • Installation source: Google Play

also using http mode (in homeassistant) vs mqtt mode.

Something seems to have changed in Android 12 with respect to the frequency at which location updates occur - at least with my particular phone. What i am observing is that in move mode, location updates seem to occur much more frequently. Prior to Android 12, they seem to occur about every 20-30 seconds. Now they seem to happen every 1-2 seconds - i am now getting thousands of API calls to my reverse geocode provider when the device is in move mode. the only setting i had changed was moveModeLocatorInterval to 20 seconds - after updating to Android 12 and seeing increased frequency, i changed it to 60 seconds thinking it may slow down the location updates. But from reading the booklet, i'm thinking this only affects how frequently owntracks actively checks for location updates - but in move mode, if it's getting gps updates from "other apps", then it's simply publishing them upon arrival, but i'm not sure i'm interpreting the booklet correctly.

I have been using tasker to change the device from significant change mode to move mode when in the car and back to significant change mode, at home. This was working great until the change to Android 12.

I am wondering if this is known/expected or something else might be going on. I am fine to abandon move mode and use siginficant change mode if i can figure out how to pick some values of locatorInterval & locatorDisplacement to get better accuracy than the default significant change mode settings. If i understand these two parameters, the location is published not more frequently than locatorInterval AND only when location has changed >= locatorDisplacement since the last publish... if that is correct, then i can play around with some values and try it out.

Is there any way to update these values dynamically? ie, can they be set by sending an Intent from Tasker? or only by remote command? (home assistant doesn't do anything to enable remote commands, so i'd have to change to mqtt mode to use that option)

@growse
Copy link
Collaborator

growse commented Feb 10, 2022

I think quite a few people have found a difference going into Android 12 with device update frequency. This has been exacerbated by different device manufacturers doing slightly different things.

What I've found (on both the emulator and on a Pixel device) is that, in move mode, you get locations at roughly double the frequency specified in moveModeLocatorInterval. If you set it to "10", they come through every 5 seconds etc.

In move mode, locatorInterval and locatorDisplacement aren't considered at all. The service just puts in a high-power, high-accuracy request with the interval sepcified by moveModeLocatorInterval (see https://github.com/owntracks/android/blob/master/project/app/src/main/java/org/owntracks/android/services/BackgroundService.java#L551). The booklet could be clearer on this, as it could be in a bunch of different places.

If i understand these two parameters, the location is published not more frequently than locatorInterval AND only when location has changed >= locatorDisplacement since the last publish... if that is correct, then i can play around with some values and try it out.

For interval, it's the other way round. The parameter in locatorInterval is passed to the Google location client and means "I want locations at least this frequently", meaning you may get them more often than specified.

Is there any way to update these values dynamically? ie, can they be set by sending an Intent from Tasker? or only by remote command? (home assistant doesn't do anything to enable remote commands, so i'd have to change to mqtt mode to use that option)

There's no intent available to allow config twiddling, and remove config / command doesn't really work on Android yet. This will come in 2.5.0 (hopefully) and provide a load more capabilities around being able to remotely configure the app either via the transport or through an intent.

@growse growse added this to the v2.5 milestone Feb 10, 2022
@growse
Copy link
Collaborator

growse commented Feb 11, 2022

What I've found (on both the emulator and on a Pixel device) is that, in move mode, you get locations at roughly double the frequency specified in moveModeLocatorInterval. If you set it to "10", they come through every 5 seconds etc.

I did some sleuthing, there seems to be some issues with the emulator because it doesn't emulate non-GPS sources of location. Also, despite asking for a PRIORITY_HIGH_ACCURACY location request, the location availability flaps between "available" and "not available" for no apparent reason on an Android 12 emulator.

On a real device (pixel 4a running Android 12), in move mode and with the app not in the foreground, I see the following frequencies:

  • moveModeLocatorInterval = 10. Time between locations published
    • average: 6s
    • min: 0s
    • max:11s
  • moveModeLocatorInterval = 20. Time between locations published
    • average: 12s
    • min: 0s
    • max:35s
  • moveModeLocatorInterval = 30. Time between locations published
    • average: 19s
    • min: 0s
    • max:48s
  • moveModeLocatorInterval = 60. Time between locations published
    • average: 41s
    • min: 3s
    • max:107s

So it turns out that the parameters we can provide to the Google client are really nothing more than a "best effort". You'll get an average interval that's the requested (or more frequent), but there's no guarantee that you'll get locations at least as often as specified.

It's also worth saying that the MapActivity maintains its own high accuracy listener, which the background service then can use to send locations more frequently. With moveModeLocatorInterval set to 60, but with the map open, I get background locations every 5 seconds.

@yajrendrag
Copy link
Author

ok. i'm not looking for frequency updates at least as frequent as X - the other way around - i want to specify X and not update more frequently than X. OR when the move distance (locatorDisplacement) has gone at least Y. given above it looks like the closest i can come is to replicate your experiment and try to pick a moveModeLocatorInterval value that produces an average near what i want to achieve for X (and understand that move mode doesn't consider locatorDisplacement). Would significant change mode work the same way with locatorInterval?

@adwuk
Copy link

adwuk commented Feb 12, 2022

That is similar to what I am seeing, albeit on Android 11. When the move mode interval is set to 10 seconds, I am getting updates of every second. When the interval is set to 60 seconds the reporting interval is between 4-5 seconds. So it always seems higher than the requested interval. Perhaps owntracks should skip the extra reporting (i.e. not send them onto the MQTT/HTTP server)? FWIW, I have "improve location accuracy" disabled as we live in a rural area, and it has the opposite effect (i.e. only 1 cellular mast about 5 miles away). With it enabled, we get some pretty random locations and the frequency of reports appears to increase.

@growse
Copy link
Collaborator

growse commented Feb 12, 2022

So the Google location client does also let you specify a fastestInterval. By default, if you just specify an interval it may deliver updates faster than that, but it works out its own max frequency. But if you specify a custom fastestInterval, then it should deliver updates no faster than that specified.

I wonder if it'd be useful to have a preference toggle that allows users to peg the fastestInterval to be the same as interval, for those that yourselves who want an upper limit on the location frequency. Would that be a good approach?

Would significant change mode work the same way with locatorInterval?

Yes, that value is what gets set as the parameter for interval in significant changes mode.

@adwuk
Copy link

adwuk commented Feb 15, 2022

I wonder if it'd be useful to have a preference toggle that allows users to peg the fastestInterval to be the same as interval, for those that yourselves who want an upper limit on the location frequency. Would that be a good approach?

Sounds like a very good approach. If you want any help with the testing I am very happy to help. I have the source downloaded and can build the app, just not got my head around the code yet :)

@growse growse modified the milestones: v2.5, 2.4.8 Feb 15, 2022
@growse
Copy link
Collaborator

growse commented Feb 15, 2022

I'll add it into the next release.

@adwuk
Copy link

adwuk commented Feb 15, 2022

I have just been for a drive around the block with a hacked version of setupLocationRequest() which simply sets fastestInterval to the same value as interval and it appears to work very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants