Android Logging

I am trying to get the logging functionality working with the current API. It seems to be working fine except not all of the data seems to be getting transferred into an arraylist that I'm trying to dump the results into.

I have a breakpoint after downloading logs and transferring data. I am seeing totalEntries 1054, but my ArrayList size is only 523. Here is my code:
protected void boardReady() throws UnsupportedModuleException {
accelModule= mwBoard.getModule(Accelerometer.class);
logModule= mwBoard.getModule(Logging.class);
float ACC_FREQ= sharedPreferences.getInt("samplingFrequency", 200);
int rangeIndex = 2;
counter = 0;
if (accelModule instanceof Bmi160Accelerometer) {
} else if (accelModule instanceof Mma8452qAccelerometer) {
((Mma8452qAccelerometer) accelModule).configureAxisSampling()
.enableHighPassFilter((byte) 0)

routeManagerResult = accelModule.routeData().fromAxes().log("accel_log").commit();
routeManagerResult.onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
public void success(RouteManager result) {
routeManager = result;
result.setLogMessageHandler("accel_log", new RouteManager.MessageHandler() {
public void process(Message msg) {
axisData = msg.getData(CartesianFloat.class);
//float x = axisData.x();
float y = axisData.y();
//float z = axisData.z();

accList1.add(counter, y);


public void failure(Throwable error) {
Log.e("test", "Error committing route", error);



  • edited March 2016
    protected void streamData() {
    mhandler.postDelayed(stopLog, 2000);

    private final Runnable stopLog= new Runnable() {
    public void run() {

    private void dlLog() {
    logModule.downloadLog(0.1f, new Logging.DownloadHandler() {
    public void onProgressUpdate(int nEntriesLeft, int totalEntries) {
    Log.i("test", String.format("Progress: %d/%d/", nEntriesLeft, totalEntries));

    if (nEntriesLeft == 0) {
    Log.i("dlLog", "Log download completed");
    counter = 0;
    //Process Data routines

    public void receivedUnknownLogEntry(byte logId, Calendar timestamp, byte[] data) {
    Log.i("test", String.format("Unknown log entry: {id: %d, data: %s}", logId, Arrays.toString(data)));
  • I have the similar issue. My logging code is similar to stu68's code snippets.

    Here are my Logs:
    the numbers represent Useful data/downloaded data/Total Downloadable data
    I/data: Progress: 149/301/3016
    I/data: Progress: 299/603/3016
    I/data: Progress: 448/904/3016
    I/data: Progress: 597/1205/3016
    I/data: Progress: 747/1507/3016
    I/data: Progress: 897/1809/3016
    I/data: Progress: 1047/2111/3016
    I/data: Progress: 1197/2413/3016
    I/data: Progress: 1346/2715/3016
    I/data: Progress: 1496/3016/3016

    The number of useful data is correct (what I expected for 2 mins' sampling at 12.5Hz). My question is why the board records twice as much data as it should?
  • And this issue is pretty consistent with API 2.3.0/2.4.0/2.5.0 with firmware 1.0.4/1.2.0.
  • For a sanity check.....

    Have you tried sending a reset command to the board before setting up logging?
  • @lgleasain

    Yes, sure.To make sure I reset the board, I even implement this 3 step connection.

    Connection Attempt 1: Reset board

    Logging logger = board.getModule(Logging.class);
    accel_module = board.getModule(Bmi160Accelerometer.class);

    Connection Attempt 2: Configure Data Routes

    Logging logger = board.getModule(Logging.class);
    accel_module = board.getModule(Bmi160Accelerometer.class);

    Connection Attempt 3: Download data
  • I'm doing the same which causes a lot of connection issues.
  • Number of log entries is not the same as number of data points.  Log entry count is only relevant for having an accurate download progress.
  • @Eric

    OK.. So is the number returned by getLogCapacity() the only reliable data about the log module?

    I also encountered with other issues while downloading the logs. Sometimes the download process gets stuck during transmission. For example, I got the callback of 70%, 80% and 90% progress but the last progress update didn't show up. This issue will cause unexpected data loss. Do you have any idea how we can solve this problem?
  • edited March 2016

    When this has happened to me it is because the log is full. You have to initiate a log clear and disconnect routine, then reconnect to get it to start working again. I have a method to clear out the logs before it fills up, but it causes complications and connection issues.

    Please vote/ request that NOR Flash be used on the Metawear boards to eliminate having to disconnect after clearing logs. See:

    We could make it available as a standard board feature, maybe a MetaWearRSUPER next year if there is enough demand for it.
  • @stu68

    I had an auto disconnect mechanism. If the download takes more than 30 seconds (preconfigured threshold), I will disconnect from the board (but doesn't clear the memory). After 2 minutes, I connect back to the sensor again and can successfully download new data points,

    With this case, I don't think the log module is full.

    Actually, I only log 2 minutes' data with frequency 12.5Hz. It should only log 1500 data points into the memory. It shouldn't fill up the memory in theory.
  • Your logging issue sounds like your device is dropping packets.  There's no rhyme or reason to why these things happen on Android; Bluetooth works very well on some devices / OSes and is shoddy on others.  The only thing I can suggest is to try on a different Android device and OS.
  • getLogCapacity() tells you total log capacity. Is there anyway to tell how much room is left or used?
  • That information is not exposed in the current API.  Does your app depend on log capacity?
  • I'm looping to download over and over. If I don't clear the log every once in a while it gets full and the app stops responding. I'm trying to determine when it's safe to perform a clear, disconnect, reconnect, etc.

    I'm using a simple counter approach right now, but doesn't guarantee.
This discussion has been closed.