Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronize timestamps across multiple devices

Tags:

android

I'm trying to synchronize the timestamps between multiple Android devices so I can kick off a task at the same time. I figure that I can use Timer and set a Date based on System.currentTimeMillis(), but the problem seems to be that the timestamps of multiple devices are just far enough apart from each other that I'm not getting the precision I want.

I'm looking at somewhere in the range of 50-100 ms, if possible. One idea I had was to use Android Beam to send one device's timestamp to the other device and then calculate a delta, but it turns out that I have to get the timestamp before the message is actually sent and received (i.e., the longer a user waits to send, the bigger the delta will be), which makes that scheme completely fall apart.

How can I sync up two or more devices so that their internal clocks will be no more than 100 ms apart from each other? Is this even possible without using an external server that keeps time?

Any other suggestions for techniques to do something across multiple devices as close to simultaneously as possible would also be welcome.

like image 604
Norman Lee Avatar asked Aug 19 '13 22:08

Norman Lee


2 Answers

Why not use the GPS time? The time tags from GPS are pretty accurate.

You could agree on all devices on a certain time and then start it when the GPS tells you to.

like image 136
Stefan Avatar answered Nov 15 '22 14:11

Stefan


Essentially, you have two choices: the simple way or the hard way.

The simple way is to use a single external source for time signals, such NIST, another internet source, or GPS as @Stefan suggests. Internet sources use NTP, see this Java NTP client question.

The hard way is to do Clock synchronization between the devices.

like image 36
andy256 Avatar answered Nov 15 '22 13:11

andy256