I don't really understand logging

I recently received a metatracker. I bought it so i can measure the temperature in my cooler using the logger module.

Unfortunately i don't really understand how the logging module works, the sample i made is using the accelerometer as test (already tried the temperature sensor). With the code i wrote i can see realtime data, but when i enable the logging module and execute logging.downloadAsync it doesn't display the logged data. This is my code, any thoughts?

`
public void connect() {

    metaWearBoard.connectAsync().continueWith((Continuation<Void, Void>) task -> {
        if (task.isFaulted()) {
            Log.i("MainActivity", "Failed to connect");
        } else {

            Log.i("MainActivity", "Connected");
            initModules();
            configureSensors();
        }
        return null;
    });
}

private void initModules() {
    accelerometer= metaWearBoard.getModule(Accelerometer.class);
    logging = metaWearBoard.getModule(Logging.class);
}

public void configureSensors() {
    accelerometer.acceleration().addRouteAsync(new RouteBuilder() {
        @Override
        public void configure(RouteComponent source) {
            /*source.stream(new Subscriber() {
                @Override
                public void apply(Data data, Object... env) {
                    Log.i("Main", String.format("Log: %s", data.toString()));
                }
            });*/
            source.log(new Subscriber() {
                @Override
                public void apply(Data data, Object... env) {
                    Log.i("Main", String.format("Log: %s", data.toString()));
                }
            });
        }
    });
}

public void read() {
    logging.start(true);
    accelerometer.acceleration().start();
    accelerometer.start();
}

public void stopLogging(){
    accelerometer.acceleration().stop();
    accelerometer.stop();
    logging.stop();

    logging.downloadAsync(100, (nEntriesLeft, totalEntries) ->
            Log.i("MainActivity", "Progress Update = " + nEntriesLeft + "/" + totalEntries)
    ).continueWithTask((Continuation<Void, Task<Void>>) task -> {
        Log.i("MainActivity", "Download completed");
        return null;
    });

}`

Comments

  • Add error handling to addRouteAsync.

  • Thanks Eric, enabling logging fixed my problem. I forgot to run metaWearBoard.tearDown() to clear up all resources.
    When i execute logging.downloadAsync the logs are being downloaded from the device, as what i expected. Now i run into the next problem, i can't seem to figure it out. I need to be able to reconnect to the device and for example download the temperature logs from the last 12 hours.

    I tried to register the task.getResult().id(), kill the app, turn off bluetooth and reconnect and tried to restore the scheduled task using timerModule.lookupScheduledTask((byte)state); but that doesn't seem to work. Any idea what i'm missing or how i should restore the scheduled task?

  • Thanks. Anonymous routes is what i was looking for, can read logs on multiple devices. Is there a way i can ask the MetaWearBoard if there is an active logging session after connecting to it on a different device?

  • @Leon said:
    Is there a way i can ask the MetaWearBoard if there is an active logging session after connecting to it on a different device?

    That's what anonymous routes does.

Sign In or Register to comment.