Logging¶
Mbientlab boards are equipped with flash memory that can store data if there is no connection with an Android device. While the RouteComponent
directs data to the logger, the Logging interface provides
the functions for controlling and configuring the logger.
import com.mbientlab.metawear.module.Logging;
final Logging logging = board.getModule(Logging.class);
Start the Logger¶
To start logging, call the start method.
If you wish to overwrite existing entries, pass true
to the method. When you are done logging, call
stop.
// start logging, if log is full, no new data will be added
logging.start(false);
// start logging, if log is full, overrite existing data
logging.start(true);
// stop the logger
logging.stop();
Downloading Data¶
When you are ready to retrieve the data, call
downloadAsync;
the method returns a Task
object that will be completed when the download finishes. There are variants of downloadAsync
that provide progress
updates and error handing during the download.
// download log data and send 100 progress updates during the download
logging.downloadAsync(100, new Logging.LogDownloadUpdateHandler() {
@Override
public void receivedUpdate(long nEntriesLeft, long totalEntries) {
Log.i("MainActivity", "Progress Update = " + nEntriesLeft + "/" + totalEntries);
}
}).continueWithTask(new Continuation<Void, Task<Void>>() {
@Override
public Task<Void> then(Task<Void> task) throws Exception {
Log.i("MainActivity", "Download completed");
return null;
}
});