What to do if my app crashes without disconnecting the board

Hello,

you know, sometimes apps do crash... In those cases, the connection with the board is not closed properly.

When this occurs, I have troubles reconnecting to the sensors, if I restart the app. The "Connecting" dialog goes on indefinitely.

Unfortunately your board doesn't have a reset button.

What can I do overcome this kind of issue?

Regards

Comments

  • I discovered that in the described situation, I try to connect to the board using the app you published on Play Store (MetaBase), it connects without any problem.

    I used the code you showcased in the "starter" app.
    • What exception is returned from the connectAsync call?
    • What is the OS and model of the Android device that is failing the reconnect?
    • Have you tried tesetting the BT adapter?
    • What exception is returned from the connectAsync call?
    No exception is thrown. The wait goes on indefinitely
    • What is the OS and model of the Android device that is failing the reconnect?
    Android 6 / Lenovo TB3 730X
    • Have you tried tesetting the BT adapter?

    Yes. In that way I can resolve, most of the times. Sometimes I had to restart the phone. But this is not optimal and users will complain. We need a reliable way of overcoming these situations.

    Thanks & Regard


  • I understand that I'm not giving concrete information to diagnose the issue. I can try to capture the logcat output next time the problem arise (BTW do you have any suggestion for filter to apply?).

    Anyway, I have two questions:
    • does the MetaBase app use the same connection code of the "starter" app?
    • is the MetaBase app source code available on GitHub? I could not find it
  • I'm seeing something similar, the call to connectAsync() never completes when trying to reconnect (the continuation is never called). In the logs I can see something similar to this:
    D/BluetoothGatt: connect() - device: EF:E0:C9:D5:67:E1, auto: false
    D/BluetoothGatt: registerApp()
    D/BluetoothGatt: registerApp() - UUID=52ae6496-0673-45f2-818d-d2ae05c948c5
    D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
    D/BluetoothGatt: cancelOpen() - device: EF:E0:C9:D5:67:E1

    Is there any way to set a timeout on connectAsync() ?

  • @Dominic

    connectAsync will timeout if a connection can't be made within 10s so its task will always complete.  Please post your connect and reconnect code.

    connectAsync itself will never throw an exception but it may fail as detailed in its Task object.  You need to add error handling to the continuation.

    So, like in your previous thread, only the Lenovo device is exhibiting this issue?

    What do you mean by "connection code"?  MetaBase also calls connectAsync if that's what you are asking.
  • Hi Eric
    Something like this:
    private final bolts.Continuation<Void, Void> onConnected =
        new bolts.Continuation<Void, Void>() {

        @Override
        public Void then(Task<Void> task) throws Exception {
            if (task.isCancelled()) {
                Log.i(TAG, "Connection cancelled");
            } else if (task.isFaulted()) {
                Log.w(TAG, "Unable to connect", task.getError());
                board.connectAsync(1000).continueWith(this);
            } else {
                Log.i(TAG, "Connected");
                /* Do connection tasks */    
                           
            }
            return null;
        }
    };

    board = service.getMetaWearBoard(btManager.getAdapter().getRemoteDevice(mac));
    board.onUnexpectedDisconnect(status -> {
        Log.i(TAG, "Unexpected Disconnect");
        board.connectAsync(1000).continueWith(onConnected);
    });
    board.connectAsync().continueWith(onConnected);

        
    Thanks for any help you can offer.
  • Ok, I can replicate the connect never finishing issue as you described.  Since that is a separate issue, we can discuss it further in a separate thread if need be.
  • Eric, yes please do. I also have that issue (connect never finishing)
    Thanks
This discussion has been closed.