Time synchronization for recording data on multiple Android devices

This question may be a little long, but open to many suggestions.


Problem:
We have several MyTouch devices at API level 8 (Android 2.2) MyTouch, which we will use to record acceleration data in an amusement park, namely a roller coaster. We also have a visualization function that allows us to display and view the points of the accelerometer depending on the time at which they were recorded. That's where we have the dilemma! The system times on Android devices are not all the same, and they cannot be installed at the same time accurate to the millisecond (only manually with a little accuracy, which is terrible).


Attempt Solution:
So, I first resorted to recording data in accordance with the GPS time found at the beginning of the application. A long short process: get the GPS time, get the system time, get the difference, and after recording the data point, get the system time again and add the difference back to the time, mark it as the start time of the recording and increase the item from there by 200 milliseconds for each recorded data. However, there are 2 problems (for getting GPS time):

  • Using getLastKnownLocation() not too accurate. In fact, this seems very inaccurate. This gives me a time that is 9 minutes from the current GMT / UTC. By the way, the system time is also about 9 minutes on an Android device ... the difference between GPS time and system time is usually from 1000 to 5000 milliseconds (1 to 5 seconds). I believe my code is wrong. I pasted it below so you can see.

  • requestSingleUpdate() would be great to use, as it would get a more recent location and possibly a very accurate time. Problem? Requires API level level 9 ... we donโ€™t.


Ideas:
Here is an idea I had, though - what if I somehow pulled global time from the site and used the time drawn from there as recording time? The problem here is that I have no idea how to do this, it's just wishful thinking mine ...

Another idea - is there some kind of global getTime() function type that I just don't know about?


The reason I want Android to pull the time from a similar watch:
Imagine two people sitting on a roller coaster - one in the front seat, one on the back. When recording data, the person in front will obviously experience acceleration a little earlier than the person in the back (and we want to see this on our visualization graph). That is why it is important for millisecond accuracy that these points are recorded according to one global time.


The code:

 Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_FINE); if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { mLocationManager.requestLocationUpdates(mLocationManager.getBestProvider(c, true), 0, 0, AmusementPark.this); Criteria criteria = new Criteria(); String bestProvider = mLocationManager.getBestProvider(criteria, false); Location location = mLocationManager.getLastKnownLocation(bestProvider); try { gpsTime = location.getTime(); systemTime = System.currentTimeMillis(); timeDif = gpsTime - systemTime; Log.e("timedif", "GPS: " + gpsTime + ", System: " + systemTime +", Dif: " + timeDif); } catch (NullPointerException e){ } } 

Update:
Here , someone offers a kind of "server" getTime() . I really like his code / answer, but what is this โ€œserverโ€ and / or how do I install it if this is the best solution?

+7
source share
1 answer

I think that the โ€œserverโ€ referenced by should configure a dedicated time server. Basically, you would set up some kind of equipment that all people who use your application will connect to in order to get time. It may be more effort than you are willing to make.

You will need the following:

  • Some spare equipment (it can be as simple as a computer running tomcat, or as complex as a dedicated server rack, depending on how many people you think your application will use.) Or a server / web subscription host

  • Some web services that simply return the time the application requests it.

  • You will need to make your server / webservice public, which is another headache.

I'm not sure if this will be your best solution, as it will depend on the network connection to access the dedicated server. There are several alternative solutions that you can try:

I do not know if your application will be public or used specifically for research. If this is the last, and it will be with a group of people you know and can coordinate, I actually recommend that you simply download ClockSync, synchronize your phones with the server at the same time, and then run your application.

If your application will be distributed among people with whom you will not have contact, then perhaps it is best for your application to connect to the same ntp server and have enough time. Here is a list of open ntp servers you can use: http://www.pool.ntp.org/en/

Here is some more info:

Clocksync

Sample code for creating an SNTP connection

I hope that the information will be useful to you when making a decision.

+2
source

All Articles