Disconnect from board side automatically after certain time

edited February 2016 in Android
I tried to add a function so that the board disconnects after inactivity a certain time. Didn't find any good API calls but tried to add a disconnect every minute with a timer. However, doesn't really look like it works or am I doing something wrong/better way to do it?

final Debug debugModule = mwBoard.getModule(Debug.class);
            AsyncOperation<com.mbientlab.metawear.module.Timer.Controller> taskResult= mwBoard.getModule(com.mbientlab.metawear.module.Timer.class)
                    .scheduleTask(new com.mbientlab.metawear.module.Timer.Task() {
                        @Override
                        public void commands() {
                            debugModule.disconnect();
                        }
                    }, 60 * 1000, true);
            taskResult.onComplete(new AsyncOperation.CompletionHandler<com.mbientlab.metawear.module.Timer.Controller>() {
                @Override
                public void success(com.mbientlab.metawear.module.Timer.Controller result) {
                    // start executing the task
                    result.start();
                }
            });

Comments

  • Nothing looks wrong with your code. Having the board trigger the disconnect may execute the failure function if it sends a nonzero status to the gatt callback.
This discussion has been closed.