linuxraspberry-piibeaconibeacon-androidntpd

Synchronize the time between an android app and a server


I use a raspberry pi with a Bluetooth dongle to simulate a beacon. I want to measure the time needed for a mobile app to detect the UUID of a beacon when I change it in the raspberry. With this code I found out the server used by the smartphone to synchronize the tile

final Resources res = this.getResources();
        final int id = Resources.getSystem().getIdentifier(
                "config_ntpServer", "string","android");
        final String defaultServer = res.getString(id); 

Than I synchronized the time in the raspberry pi with

sudo ntpdate -u 2.android.pool.ntp.org

Before I change the id of the beacon I print the time

timestamp() {
  date +"%T,%3N"
}


timestamp # print timestamp

sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1.....

Then I compare the time when I changed the UUID and the time in the logcat when the UUID was seen for the first time and the result is alwayse negative UUID changed at 15:33:03,276 and detected at 15:33:02.301.

Is this a synchronization problem? Is there a better way to do this?


Solution

  • A few thoughts:

    What you are showing is a detection time of about -1.0 second. This suggests that the time is not synchronized well. I would suspect the Pi is the problem and troubleshoot there. It might be helpful to show the time to the millisecond on both devices side by side to troubleshoot.