Starting up accelerometer logging on boot

edited May 2017 in Android
Hi Eric,

I am trying to teach Metawear C to log accelerometer readouts right after boot and I have troubles putting it correctly together.

The problem is with accelerometer and logging start commands. If I put them as in the code below, the logging never starts after reboot as if the continuation task is invisible to the macro. I need to connect to the board, run this code again and from this point logging starts working perfectly.

I tried two other alternatives... If I place accelerometer and logging start in Place A in the code, reboot the board, connect to it and dowload log all hell seems to break loose. I get lots of NullPointerExceptions from the board as if there is some thread race going on (understandable as I probably start logging before the route has been set up properly).

If I place acceloremeter and logging start in Place B in the code, reboot the board and connect to it and download the log it looks like the logging has started after reboot, but there is no acceloremeter data there. I download some data logged before reboot and then hundreds of empty log entries.

Do you have an idea how can I implement it properly?


  •         macro.startRecord(true);
    accelerometer.acceleration().addRouteAsync(new RouteBuilder() {
    public void configure(RouteComponent source) {
    to().split().index(0).log(new Subscriber() {
    public void apply(Data data, Object... env) {
    Log.i("MainActivity", "x = " + String.format("%.2f", data.value(Float.class)));
    // *** Place B ***
    }).continueWith(new Continuation<Route, Void>() {
    public Void then(Task<Route> task) throws Exception {
    Log.i("MainActivity", "Accelerometer started");
    Log.i("MainActivity", "Logging started");
    return null;

    // *** Place A ***

    macro.endRecordAsync().continueWith(new Continuation<Byte, Void>() {
    public Void then(Task<Byte> task) throws Exception {
    Log.i("MainActivity", "Macro ID = " + task.getResult());
    return null;
This discussion has been closed.