Synchronizing time between smartphone and pc/embedded device

1.9k views Asked by At

I have to measure and verify the latency of messages being sent wirelessly via WiFi/Bluetooth from smartphone to pc. The distance varies between 5 and 10 meters.

Example: message sent from smartphone at time X, received and processed at time Y. Duration: 35ms.

Since these messages are non-trivial (safety and security commands to further machines) its neccesary to synchronize the time between the smartphone and the pc to the most precise accuracy(milliseconds).

This was an easy task using net time for two PCs connected via LAN, but I'm uncertain with smartphones using iOS/Android..

Is it accurately enough to lets say sync both, smartphone and PC with NTP time, or do you know a better way to synchronize time between them?

From what I read, synchronizing time with NTP provides accuracy from ~ 1 to 20 ms. But this range is too vague..

Does anyone had similar problems?

2

There are 2 answers

4
NickOverflow On BEST ANSWER

Must this all be handled over the network or have you considered a physical timing trigger between the two?

If they are located near each other, I would recommend using a O-Scope. Sending a timing pulse from the phone's headset saying the message was sent. Then a Pulse from the PC that it was received and processed, via serial port or such.

If you use this route, you would want to take into account the latency between when the SW sends the command and when the pulse is sent out the hardware. I would do this using a tight loop that just toggles the signal, then see what the frequency is. Your latency for each would be half the period. And your total latency would be the difference between the PC and Phone's latency (which could be positive or negative).

0
poabloa On

With a rooted Android smartphone, it is possible to use PTP to synchronise the time between itself and a computer. PTPd (https://github.com/ptpd/ptpd), or PTP daemon is the implementation of the protocol. It is able to achieve micro- and nano-second accuracy which is good news if you're measuring on the milli-second level.

The only caveat is that it only works on Ethernet and WiFi - synchronising on 4G and 5G networks seems to not function at all.