Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoConnect=true attempts to reconnect even after invoking disconnect() #26

Closed
ghost opened this issue Sep 27, 2018 · 8 comments
Closed
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Sep 27, 2018

I'm trying to disconnect from a device with a connection attempt in progress, but apparently the disconnect is never executed (I never receive any callback) and the autoConnect=true causes an undesired reconnect attempt

Steps

  1. Invoke connect.await() on a switched off device
  2. After some seconds, invoke
        disconnect()
                .done { Timber.d("disconnect success") }
                .fail { device, status ->
                    Timber.d("disconnect fail")

                    close()
                }
                .enqueue()
  1. After some time, connect.await() throws a RequestFailedException: Request failed with status 133 and immediately attempts to reconnect. None of the disconnect callbacks is invoked

Is this working as intended or is it a bug?

@ghost
Copy link
Author

ghost commented Sep 27, 2018

This fixes the issue for now, but it's not pretty

This is a wrapper that holds the BleManager class

public void connect() {
    forceDisconnect.set(false);
    bleManager.setGattCallbacks(this);

    try {
      bleManager.connect(bluetoothDevice).await();
    } catch (RequestFailedException | DeviceDisconnectedException | BluetoothDisabledException e) {
      if (forceDisconnect.get()) {
        bleManager.setGattCallbacks(this);

        bleManager.close();
      }

      e.printStackTrace();
    }
  }

public void disconnect() {
    forceDisconnect.set(true);

    bleManager.disconnectWithoutReconnect();
  }

@philips77
Copy link
Member

Hi, I'll look into it. Thanks for the report!

@philips77 philips77 self-assigned this Sep 28, 2018
@philips77 philips77 mentioned this issue Sep 28, 2018
@philips77
Copy link
Member

Hi @maragues-kolibree,
I was thinking about what should actually happen in this case.
First of all, the correct way of closing pending connection attempt is by setting a timeout. This may be set wither using enqueue(int) or await(int). The PR makes sure the connection gets cancelled in such case.
Also, the lib won't start another connection if the first one failed dues to a timeout.

@ghost
Copy link
Author

ghost commented Sep 28, 2018

If you release a new beta, I can test next Monday

philips77 added a commit that referenced this issue Oct 1, 2018
This PR fixes issue #27 and helps with #26.
@philips77
Copy link
Member

I released beta3.

philips77 added a commit that referenced this issue Oct 1, 2018
@philips77
Copy link
Member

Fixed in beta4 :)

@ghost
Copy link
Author

ghost commented Oct 1, 2018

It's fixed, congrats and thanks!!

It's beta3, not beta4, just to keep track for the future.

@ghost ghost closed this as completed Oct 1, 2018
@ghost
Copy link
Author

ghost commented Oct 1, 2018

After this change, is there a way to invoke connect in a way that it keeps trying to reconnect after an error?

I know we can do it manually, just wondering.

@philips77 philips77 added the bug label Oct 2, 2018
@philips77 philips77 added this to the Version 2.0 milestone Oct 2, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant