Clock synchronization
Hello,
I have an app that connects to metawear device,
starts sensors and logger, disconnects, and moves on to another device
to do the same. It later connects to them one by one again to download
logs.
I sometimes find that the base timestamp on the log I have an app that connects to metawear device,
starts sensors and logger, disconnects, and moves on to another device
to do the same. It later connects to them one by one again to download
logs.
captures is incorrect (for example dated a week earlier than the capture
actually started), but it actually has the data from the last capture: so correct data, incorrect timestamp.
Do
you have any idea how I might be ending up with an outdated timestamp?
When exactly does the android API store the timestamp? How does the
timestamps get synchronized if there are old logs in the flash that were
not retrieved (but will be retrieved next time I do a download)?
And how does this work with the new anonymous routes (I have not yet tested this feature). If logs can be retrieved from a different Android device, then surely the base timestamp is stored in the metawear board.
Metawear android SDK: 3.2.2
Firmware version 1.3.3/1.3.6
Thank you,
Veronica This discussion has been closed.
Comments
However, I would like to understand which is the event/API call that triggers this timestamp storage. Because for some reason this is not always happening in my case, and it is using a week old timestamp.
And also how this works when there are old logs in the board.
In my case, the board does not lose power.
When I say old logs I mean day old logs. The device was neither powered off, nor resetted.
The timestamps are all incorrect by the same amount, as if the base epoch used is incorrect.
It looks like my issue is solved. It is somehow related to serialization, but I don't know exactly how. In any case, if possible, could you explain about the reference point of the timestamp for future reference?
Thank you,
Veronica
I'm not going to explain in further detail how timestamp works. You can look through the API implementation if you want specifics but they do not affect your usage of the API (which is the point of having an API).
Hello! I ran into the same issue but was unable to reproduce it.
I have three MetaMotion C devices and all are logging data. Two of the sensors produced data with correct timestamps. The third device produced data with a timestamps that were offset by -57,123 seconds (which is the time I finished testing the night before).
The sequence was:
I did this entire sequence three times and on the third run, the logger for the first device had incorrect timestamps.
Decided to see what's actually going on here:
From the code in LoggingImpl class, it looks like we have three data types and four variables:
a "resetUid" is presumably an identifier generated on the sensor board which marks a new logging session (so we get a new value after calling logging.clearEntries() and disconnecting)
a "tick" is a presumably generated by the board whose value is auto-incremented in a fixed period (LoggingImpl.TICK_TIME_STEP milliseconds)
a "TimeReference" is a tuple that binds a resetUid to a tick value and the system's time
rollbackTimestamps - a map from resetUid to tick (looks like this is used both to preserve offsets when a disconnect occurs during download and to ensure we don't re-process the same data on a re-download)
logReferenceTicks - a map from resetUid to a valid TimeReference object
latestReference - the last TimeReference seen
lastTimestamp - a map from resetUid to the last tick sent from the board for this resetUid
On connectAsync (line 734), we call logger.queryTime:
Later, when we receive an event (READOUT_NOTIFY):
Questions:
1. Could it be that the board produced a resetUid value which was seen by the app the day before?
2. Mutability of TimeReference object
- Why not just store the calendar time and starting tick once and calculate all your offsets based on those?
- Is it possible you have a race condition in here? Is that responseHandler callback on line 279 ever invoked concurrently?
3. Usage of legacy Calendar class
- I assume there's a reason for this, e.g. backwards compatibility but there's http://www.threeten.org/threetenbp/ which provides backwards compatible immutable DateTime objects
- that Calendar.clone call forces an object allocation per event, is this really necessary as opposed to just tracking raw timestamps instead? I'll assume benchmarks show this isn't causing memory/perf issues ...
2) It doesn't matter if time references change; everything is relative offsets from a fixed point in time. However, the reference points probably should not change while the board is actively logging.
3) Does that library offer any features that is required by the current API implementation?
Ok! Will update thread if I reproduce again
I wouldn't say it's "required", but Calendar class has been deprecated in favor of the newer Date, DateTime, etc classes in java.time package since JDK 8 release back in 2014. See this link and this one.
I'm not opposing a copy, but in general it's more expensive to copy an object than a long.
Thanks for the response!