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

Connect with bonding fails #1641

Open
HarrievanWinden opened this issue Sep 26, 2024 · 0 comments
Open

Connect with bonding fails #1641

HarrievanWinden opened this issue Sep 26, 2024 · 0 comments
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend

Comments

@HarrievanWinden
Copy link

HarrievanWinden commented Sep 26, 2024

  • bleak version: 0.22.2
  • Python version: 3.11
  • Operating System: Windows11

Description

I've been trying to make a BT connection to a BLE device which uses "just works" to connect.
But when trying to bond to the device i'm getting a pop-up on the bottom right corner from windows. With the text "click to add a device". When clicking on this pop-up mt BT settings will open and a seperate pop-up wille open with "unknown device", "bonding failed".

What I Did

This is the code i use at the moment.

    async def scan_for_devices(self, timeout=5.0):
        """Scan for available BLE devices and return a list of device names and MAC addresses."""
        devices = await BleakScanner.discover(timeout=timeout)
        return [(device.name, device.address) for device in devices if device.name]

    async def connect_to_device(self, mac_address):
        """Connect to the selected device by its MAC address."""
        self.client = BleakClient(mac_address)
        try:
            await self.client.connect()
            self.connected_device = mac_address
            print(f"Connected to {mac_address}")
            return True
        except Exception as e:
            print(f"Failed to connect to {mac_address}: {e}")
            return False

One of my findings where that this issue is only on windows. MacOS has no trouble with the pairing/bonding using this code.

Also i found out this issue does not occur when bonding has already been done before using another app e.g. "Bluetooth LE Explorer"

Logs

Failed to connect to {mac_adress}: [WinError -2147483629] object has been closed

orignial:

Failed to connect to {mac_adress}: [WinError -2147483629] Het object is gesloten

Let me know if i can add any extra information if needed.

Thanks in advance.

@dlech dlech added the Backend: WinRT Issues or PRs relating to the WinRT backend label Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: WinRT Issues or PRs relating to the WinRT backend
Projects
None yet
Development

No branches or pull requests

2 participants