Is there a way to synchronize clocks with the Microsoft Band using the SDK?

91 Views Asked by At

I'm working on a project where I need sensor data readings from the Band and a connected smartphone to be synchronized. Thus, I need to be able to find out the clock difference between both devices. Events contain a timestamp, which I could use for synchronization, but this would require a way to reliably force the Band to send a sensor reading directly on request.

  1. The smartphone requests a sensor reading from the Band (f.e. by registering an event listener) and notes the local time t1 of the request transmission
  2. The Band receives the request and directly responds to it, sending its local timestamp s1
  3. The smartphone receives the response at local time t2.

Now, the smartphone can approximate the connection delay d = (t2 - t1)/2 and can set its local time to s1 + d to approximately synchronize with the Band. This protocol only works properly if the Band responds within a reasonable time.

Does getSensorManager().registerXXXEventListener() behave like this or is there a possibility that it delays the response (f.e. to save energy)? If it may introduce delays, is there some other way to get the Band's current time?

2

There are 2 best solutions below

2
Joe Healy On

Grab a sensor and hook the appropriate timestamp? Don't have band with me but I believe ISensorReading:: Timestamp comes from the device?

As defined, pulled out of object browser...

Let us know if this works...

namespace Microsoft.Band.Sensors
{
public class BandSensorReadingEventArgs<T> : EventArgs where T : IBandSensorReading
{
    public BandSensorReadingEventArgs(T reading);

    public T SensorReading { get; }
}
}

System.DateTimeOffset Timestamp { get; } Member of Microsoft.Band.Sensors.IBandSensorReading

    private async void HeartRate_ReadingChanged(object sender, BandSensorReadingEventArgs<IBandHeartRateReading> e)
    {
        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
        () =>
        {
            TextBlock_HeartBeatStatus.Text = e.SensorReading.HeartRate.ToString();
            DateTimeOffset timestamp = e.SensorReading.Timestamp;
        });
    }
    private async void Accelerometer_ReadingChanged(object sender, BandSensorReadingEventArgs<IBandAccelerometerReading> e)
    {
        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
        () =>
        {
            string status = 
            $"x:{e.SensorReading.AccelerationX.ToString("F1")} y:{e.SensorReading.AccelerationY.ToString("F1")} z:{e.SensorReading.AccelerationZ.ToString("F1")}";       
            TextBlock_AccelStatus.Text = status;
        });
        DateTimeOffset timestamp = e.SensorReading.Timestamp();
    }
1
Heribert On

There seems to be an automatic synchronization. If you set the clock of the band to some other time and print the timestamp of the SDK you will notice that it corresponds to the phone time, not the band time. So I guess there is no need for time synchronization between phone and band.