Logging time reduced when using Android SDK
I have been using the Android SDK for connecting to a Metawear C. I am facing a problem while logging data. When I use the Metabase Android App, I am able to log nearly 295 seconds of data. At the same time, when I use the SDK to log data, I am initially establishing a connection with the board. After which I am starting to log data. When I stop the logging after around 5 minutes, I am many a times finding that the board logged data only for a minute or two.
Initially I thought that it was a problem because I was using "false" for overwrite. But even after replacing it with "true", I am finding the same issue.
One thing that I noted was, I can log for a longer time on my own app after I log using the Metabase app. Hence, another attempt at resolving the issue was to use logging.clearEntries(). That didnt help either. I am facing the same issue.
I am not sure what I am doing wrong. Clearly my implementation of using the logging sdk is wrong. Would really appreciate some help with best practices/sequence of events to log the data properly.
Comments
What sensors are you using?
Post relevant code snippets of your app.
My Target Android SDK version is 28. Metawear SDK version is 3.6.2.
I am only using the accelerometer.
The frequency is 12.5 Hz and the ODR is 2g.
I have 4 Buttons (connectButton, disconnectButton, startLogging and stopLogging) and 1 TextView (status)
I ran some tests and am posting my output below
Log Iteration 1:-
Received Logged data is for 112.901 s
Log Iteration 2:-
Received Logged data is for 60.981 s
Log Iteration 3:-
Received Logged data is for 38.299s
Log iteration 4:-
Received Logged data is for 83.406s
Log Iteration 5:-
Received Logged data is for 0.0s
I don't receive any data after the 4th iteration. The 4th iteration has a total cumulative logging time of 295 s. Which means that the flash memory is full at this time. But since I am using,
If I understood the documentation correctly, it should not matter anyway if the flash memory is full or not since the device is supposed to just overwrite the values with the latest readings from the accelerometer. Did I understand wrong?
As soon as I log using the Metabase App and then log with my application, I am able to log data again.
The device doesnt log data even if I remove the battery and reset the device. Which leads me to believe that the Metabase App uses some call that erases all the data saved on the flash when I choose to stop logging and download the data.
Edit
I tried the same with
and ran into the same problem.
Another thing that I noticed is that, if I rerun my application by changing the boolean values in the function
the logging works and I can download the logged data. Which in the previous case happened only after I ran the Metabase App.
I don't mean to spam. I am just posting results from the experiments I am running to see if any of it can help identify where the problem is.
I ran another experiment to see what happens if I log more than 5 minutes of data comparing both boolean values.
Case : overwrite=false
Difference between starttime and first reading from the log - 678 milliseconds
This would be the time required for the android device to send the command and the Metawear device to start reading sensor values.
Difference between endtime and last reading from the log - 61,040 milliseconds
This indicates that as soon as the flash memory is full, the device stops taking readings.
Conclusion: Works as expected. Any new values after the flash is full is discarded.
Case : overwrite=true
Difference between starttime and first reading from the log - 736 milliseconds
This would be the time required for the android device to send the command and the Metawear device to start reading sensor values.
Difference between endtime and last reading from the log - 49,660 milliseconds
This indicates that as soon as the flash memory is full, the device stops taking readings.
Conclusion: Works the same as when overwrite is false? I expected a large difference between the starttime and the first reading indicating that whatever values the device logged initially would be deleted for the new values. Instead we got a large difference between the stoptime and the last logged timestamp.
Should I post this as a different discussion? Since it may have nothing to do with the problem stated.
What are the specs of your board? Post a screen shot from the MetaBase diagnostic screen.
Add a LogDownloadErrorHandler to the
downloadAsync
function.I changed the
LogDownloadUpdateHandler()
toLogDownloadErrorHandler()
and LoggederrorType.name()
. I didnt get a Log in Logcat so I assume the Download Error never occurred.In the log tests that you posted, did you ever disconnect from the board in between the tests or did you go straight into another round of testing after the log download completed?
I went straight into another round of testing.
However, I am unable to log and download more data even if I disconnect, connect again and start logging.
I even reset the board by introducing ``debug.resetAfterGc()''and it didn't work. I have to restart my app to get the device to log data.
For MetaWear C, the firmware cannot erase the time flash memory while connected so you need to disconnect after the log download completes.
The main problem in your code is that you are only adding the data route once. Routes are no longer valid if the board resets or you call
tearDown
.Ok. I didn't know that. Do either of MetaMotion C or MetaMotion R support the functionality of erasing flash memory when connected?
Yes. This was my mistake. I didnt reset accelerometer to null when the disconnect was successful. Including that in the successful disconnect solved the problem. I can now log the data after I disconnect when the flash is full.
One last thing I wanted to confirm was that
logging.start(true)
will never work in case of a MetaWear C since the flash memory cannot be overwritten when connected?MetaMotion boards should be able to erase while connected though logging while connected is not a normal use case.
Typically, if you can maintain a stable connection, you would stream the data. If instead, you need to log, you would periodically connect only to sync the data.
That is correct. Though this raises the question of why you are logging data if you have a stable connection with your Android device.
I am working on a time intensive use case of the accelerometer data. Hence, I need the timestamps on the data to be as accurate as possible. I ran a test initially with Streaming and Logging and found that while streaming, I get data at odd intervals though I have set the frequency at 12.5 Hz. I have the following example.
I have used
data.timestamp().getTimeInMillis()
as the function to get the timestamps. Ideally, the timestamps for consecutive datapoints should be 80 ms. However as we see, the difference between the timestamps of two consequent datapoints are very erratic.While with logging, I got more or less the same time difference between two datapoints. Hence, though I have a connection established at all times, I decided to use logging instead of streaming.
By any chance is the timestamp difference expected to be so erratic in case of Streaming Data?
https://mbientlab.com/androiddocs/3/data_route.html#account
That worked perfectly for streaming. Thankyou very much for your help @Eric.