Can't connect to Bluetooth device before nRF Connect connecting and then disconnecting Bluetooth device
- bleak version: 0.15.0a1
- Python version: 3.10.5
- Operating System: Windows 10
Description
python3 .\main.py
Waiting connecting to ANCS1
E8:20:9F:75:90:08
Exception in thread Thread-1 (thread_function):
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\locks.py", line 214, in wait
await fut
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\tasks.py", line 456, in wait_for
return fut.result()
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "D:\main.py", line 173, in thread_function
loop.run_until_complete(run_uart(bt_mac_address, loop))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "D:\main.py", line 99, in run_uart
async with BleakClient(address, loop=loop) as client:
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\bleak\backends\client.py", line 61, in __aenter__
await self.connect()
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\bleak\backends\winrt\client.py", line 268, in connect
await asyncio.wait_for(event.wait(), timeout=timeout)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\tasks.py", line 458, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
Traceback (most recent call last):
File "D:\main.py", line 190, in <module>
time.sleep(0.01)
KeyboardInterrupt
After using nRF connect APP to connect and then disconnct Bluetooth device. Bleak can connect to Bluetooth device. PS D:> python3 .\main.py Waiting connecting to ANCS1 E8:20:9F:75:90:08 D:\main.py:102: FutureWarning: is_connected has been changed to a property. Calling it as an async method will be removed in a future version x = await client.is_connected() client.is_connected() True
The following is log from Nordic nRF52832 device when connecting failed.
0>
The following is log from Nordic nRF52832 device when connecting successfully.
0>
The following is another log message related bleak.
python3 .\main.py
Waiting connecting to ANCS1
E8:20:9F:75:90:08
Exception in thread Thread-1 (thread_function):
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "D:\main.py", line 174, in thread_function
loop.run_until_complete(run_uart(bt_mac_address, loop))
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 646, in run_until_complete
return future.result()
File "D:\main.py", line 99, in run_uart
async with BleakClient(address, loop=loop) as client:
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\bleak\backends\client.py", line 61, in aenter
await self.connect()
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\bleak\backends\winrt\client.py", line 276, in connect
await self.get_services()
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\bleak\backends\winrt\client.py", line 452, in get_services
await self._requester.get_gatt_services_async(
OSError: [WinError -2147483629] 該物件已關閉。
Traceback (most recent call last):
File "D:\main.py", line 191, in
OSError: [WinError -2147483629] 該物件已關閉。
This is probably a duplicate of #1061