Data synchronization in Android

Hi Everyone,

I have a need to save data from a few bluetooth devices in a synchronized way. The metawear CPro being one of those devices. Say I want to synchronise the onboard accelerometer data from the android phone with the data coming in from the Metawear device (MW for short). I set the data stream sampling frequency on the MW to 50Hz and start the stream.

The message.getTimeStamp() method has an inconsistent time difference between consecutive events and I think that may be due to the getTimeStamp operation is taking some finite amount of time. Is this true ?

Does anyone know how best to ensure that I can transform the data I get from the MW to be synchronised with that of the phone ? So I can draw it on the same graph.

Comments

  • You cannot get accurate timestamps from a live stream.  The accelerometer produces data at consistent intervals so you can rely on the 50Hz setting as a reliable time offset between two data points.
  • Okay, thanks for the quick response. 

    I can work with this. All I need to get is a timestamp of when the stream starts. Which I presume can just be called by message.getTimeStamp for the first entry. Correct ? (Seems like a simple question but I did read somewhere that getTimeStamp may log the time that the message is received, rather than when its sent, which is correct ?)

    Furthermore, as I'm using bluetooth there is a non-zero chance of packet loss. If I'm using a constant offset between streams how can I be sure that the data wont drift ? Is there an incremented counter I can make use of ?

    Best Regards,
    Rob
  • 1) Yes.

    2) You have the sampling frequency and start time.  Using those two variables, you can approximate how many data points you expect to see at a point in time and check that you have received the expected amount.
  • Hi again Eric,

    While I get this method works in theory, in practice, for my application its not accurate enough. If possible, I'm thinking of logging the data for a period of time then sending that array to the phone at regular periods of time. So log the data for a minute in one array, send this, while logging in another, then alternate.

    Could you tell me if this is possible with the current Android API

    Thanks for your continued support.
  • What do you mean by "it's not accurate enough"?  First off, are you receiving the expected amount of data?

    No, the logger cannot free the flash memory while a btle connection is active.  If you are streaming at a slow enough rate, you might be able reconnect fast enough.  However even if this weren't an issue, the sensors could fill the logger faster than you can download it depending on your data rate.
This discussion has been closed.