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

add auto_connect for android #1644

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

tomaszduda23
Copy link

Pull Request Guidelines for Bleak

Before you submit a pull request, check that it meets these guidelines:

  1. If the pull request adds functionality, the docs should be updated.
  2. Modify the CHANGELOG.rst, describing your changes as is specified by the
    guidelines in that document.
  3. The pull request should work for Python 3.8+ on the following platforms:
    • Windows 10, version 16299 (Fall Creators Update) and greater
    • Linux distributions with BlueZ >= 5.43
    • OS X / macOS >= 10.11
  4. Squash all your commits on your PR branch, if the commits are not solving
    different problems and you are committing them in the same PR. In that case,
    consider making several PRs instead.
  5. Feel free to add your name as a contributor to the AUTHORS.rst file!

@dlech
Copy link
Collaborator

dlech commented Sep 29, 2024

Can you describe the intended use for this feature? Typically, with Bleak, we always scan and then connect.

@tomaszduda23
Copy link
Author

tomaszduda23 commented Sep 29, 2024

There are restriction on scanning in android. It works each time when device is awake. When screen is off it fails in active and passive mode. Without this connect fails randomly when screen is off.

@dlech
Copy link
Collaborator

dlech commented Sep 29, 2024

I'm not sure I fully understand. You are saying that the restriction is with scanning, but the change is in BleakClient, not BleakScanner.

@tomaszduda23
Copy link
Author

I'm sorry form mixing this up. Those are two separate things.

  1. If you know device address already it is possible to connect without scanning.
    a) E.g. you can have stored last device which was used in settings. Than you can connect without scanning.
    b) Or you can scan when screen is on and connect from time to time when screan is off. When using auto_connect = True android blocks until device is available.
  2. BleakScanner.discovery fails if scan is done from service when screen is off. It is not related to this PR. I just mention this for reference. That might be caused
    https://developer.android.com/reference/android/bluetooth/le/ScanSettings#SCAN_MODE_LOW_POWER

@dlech
Copy link
Collaborator

dlech commented Sep 29, 2024

  1. When using auto_connect = True android blocks until device is available.

This is how all other OSes work, so it sounds like we want auto_connect = True all of the time (with a timeout). This way, Bleak works the same on all platforms.

@tomaszduda23
Copy link
Author

It seems that both are needed depending on remote device configuration https://stackoverflow.com/questions/40156699/which-correct-flag-of-autoconnect-in-connectgatt-of-ble. If remote device do not advertise it would never be available I guess. Doc says.

autoConnect
boolean: Whether to directly connect to the remote device (false)
or to automatically connect as soon as the remote device becomes available (true).

My understanding is that true waits for advertisement from remote. false try to immediately connect to device which was "bonded" already. I can be wrong though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants