How to synchronize two Android Phones Clock (upto msec)? or Get EXACT difference?
Asked Answered
A

0

19

People! I thought to include it in original question but didn't.
WHILE VOTING, YOU ARE ALLOWED TO COMMENT WHY DID YOU VOTE?
Please use it to enable learners get theirs things done and convey their thoughts/issues to others better way. Not everyone knows what you think. Thanks

In Short: I need to synchronize clocks of two Android Phones (placed close to each other OR not; both cases) with each other AND with up to an accuracy of a few milliseconds (10, 20 ms max).

  • Either sync the clocks
  • Or get an offset of one from the other

What I am Doing: I have a developed app that I am using to measure different GSM network statistics. I am using telephony manager to get three states (OFF-HOOK, IDLE, RINGING). Phone A calls phone B. Both phones are running an app that is saving the time-stamps with regards to the states mentioned above. After making many calls I export the time-stamps in a data file and analyze them to get different network stats.

What is my Issue: I have to cross-match the time-stamps to get stats. Now the problem is that if the phones' clocks are not synced then I will not be able to get exact stats (e.g. how much time it takes to get phone B in ringing state after phone A initiates a call?).

What I have Tried: So far I have tried to sync clocks with NTP, GPS or atomic clock. I have used ClockSync (Android app) to get offset of both phone clocks from atomic clock. The issue is that this offset depends on RTT of network packets from my phone to server. I gives my difference of up to 100 ms when I check offset two times (tap refresh two times consecutively). The offsets at both phones can lead to error of up to 200 ms which is unacceptable for me.
All other syncing apps/methods have same issue.

Possible way forward: (What I think). I may develop an app that

  • takes the time-stamp at phone A
  • transfers that to phone B via Bluetooth or WiFi (connected to same router),
  • B then compares that time-stamp with its own clock, calculates offset,
  • And I run my original app, run experiments and,
  • Use the offset to correct time-stamps before processing data

Your Comments/Suggestions: How to do it? And comments on the method described in last part..

Animate answered 10/6, 2016 at 12:24 Comment(6)
First you need to take into account the network latency, so while your idea might work, you could have a huge spike in latency exactly when you try to sync the clocks. So what I would do is do the measuring of the time difference more than once (maybe about 20-50 times) and get an average difference of the clocks. Then you need to factor out the time the network added to your measurement, for this you could ping the other device (again 20-50 times to get an average) and substract this network latency from your estimation. This should give you a pretty accurate synchronization of the clocks.Scrutable
Additionally, while doing this, you could use a low-pass filter on the time difference measurements to filter out spikes in latency.Scrutable
I don't know why people would downvote this, as I find it an interesting question actuallyScrutable
@A.Steenbergen Yes, I plan to take many measurements and have them averaged out. So that to ignore any spikes. BTW thank you for your support :)Animate
I also have this problem and I tried all method which you mention and after i tied with this problem, may be possible with use of NDK in code but i don't know how to do. I think this is biggest problem which I faced in my life.If you found any solution please let me know.Trangtranquada
See how NTP worksEthicize

© 2022 - 2024 — McMap. All rights reserved.