Sync Android devices via GPS time?
Asked Answered
G

3

21

Short version:

Problem: I need several Android devices to do something at the exact same time (within ca 100 milliseconds). For example, I want all devices to play a certain sound at previously determined point in time.

Question: Could I use GPS time to make sure the devices clock's are synced?

Longer version:

Several people having Android devices are in the same outdoor location (for some specific sports event). All devices should signal certain events at the exact same time. (What time will be determined before hand and it is not important that they do it at exactly that time, as long as they do it at the same time). FWIW: those events will help the people to start their sporting activity at the same time.

Here are assumptions I can make:

  • There may or may not be cell coverage. (It is outdoors and may be far of urban areas)
  • The devices may or may not be connected to the internet. (Some people might not have a data plan)
  • Devices can talk to each other. If the devices are not connected to the internet they will be connected via wifi (though the wifi may not have an internet gateway).
  • The devices are outside (and not inside buildings). (That's good, it means all devices can get a GPS fix)
  • The devices are physically close to each other (i.e., within 300 m2). (Not sure if that's important)

I cannot use the internal clock to know when to play events: users can manually change the time and even if a device is set to get the time from a cellular network, that network might not provide the exact right time. Two devices might be booked into different networks and hence their time might not be synced very well.

At app startup, each device could ask for a GPS fix and save the difference between the GPS time and its internal clock. Now the master could announce events based on this GPS time (by using it's internal clock and substracting the offset it saved earlier).

Will this be precise enough and reliable?

Many thanks in advance, Andreas Leitner

Glasses answered 21/11, 2011 at 10:21 Comment(3)
you can use the app GPS Time from the market market.android.com/details?id=net.sourcewalker.gpstimeRoughish
That's a great idea. I can use this app to try out if it works. Eventually I'd like to build this functionality into my app though. I don't want to ask my users to install another app (even though they don't need it) and even more problematic one that requires root access.Glasses
Hi, i am pursuing the same thing. Were you ever able to achieve this?Spinal
G
13

You can get the time difference in milliseconds from currentTimeMillis() and Location.getTime() in the onLocationChanged() callback. Use requestSingleUpdate()


I just want to add that, if the user has a data connection they can use NTP time, which is even more accurate, as the GPS internal clock might drift and correcting it takes a while.


EDIT: I want to edit this answer. After working as a GNSS developer in Android OS I realized that many 'major' Android OEMs have messed this up. Usually NMEA sentences are generated at the chipset or GNSS stack. Sometimes the time is right, it depends on the implementation.

Also there is a problem of leap second. GPS time is not UTC time. And as of this writing it is 18 seconds ahead.

Also GPS time fromLocation objects are now system time as per the documentation

TLDR : use NTP time

Galla answered 21/11, 2011 at 10:50 Comment(1)
Sounds great. I don't need to change the system time. It is enough if every device (which has my app installed) calculates that offset and hence can work with a common reference time.Glasses
C
2

You cannot rely totally on the GPS time as there is a known issue for some devices that the time retrieved for some devices is one day ahead. In that case you might get a big offset.

http://code.google.com/p/android/issues/detail?id=23937

A workaround for solving this issue has been discussed here: Android : Samsung Galaxy Tabs and Android 2.2 Devices Showing GPS date 1 Day Advance from 1st jan 2012

Corody answered 23/10, 2012 at 6:13 Comment(0)
M
0

UTC is not derived from GPS, APK overrides GPS. Android set to ignore GPS clock. You are getTime() is NIST. not GPS

Minos answered 12/7, 2015 at 22:41 Comment(1)
If this is supposed to be an answer to the original question, then you need to improve it.Hewes

© 2022 - 2024 — McMap. All rights reserved.