Bleak can't connect on ubuntu
See original GitHub issue- bleak version: 0.4.3
- Python version: 3.7.3 & 3.6.8
- Operating System: Xubuntu 18.04
- bleak version: 0.4.3
- Python version: 3.6.8
- Operating System: Lubuntu 19.04
Description
Bleak randomly throw an exception during any connexion attempt on linux (almost every time):
me@my-computer~$ python3 test.py
Traceback (most recent call last):
File "/home/me/.local/lib/python3.7/site-packages/bleak/backends/bluezdbus/client.py", line 98, in connect
).asFuture(self.loop)
txdbus.error.RemoteError: org.bluez.Error.Failed: Software caused connection abort
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 25, in <module>
loop.run_until_complete(run(address, loop, True))
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "test.py", line 18, in run
async with BleakClient(address, loop=loop) as client:
File "/home/me/.local/lib/python3.7/site-packages/bleak/backends/client.py", line 41, in __aenter__
await self.connect()
File "/home/me/.local/lib/python3.7/site-packages/bleak/backends/bluezdbus/client.py", line 100, in connect
raise BleakError(str(e))
bleak.exc.BleakError: org.bluez.Error.Failed: Software caused connection abort
What I Did
Pasted this program in a file named test.py
and then launched it.
import asyncio
from bleak import BleakClient
async def run(address, loop, debug=False):
async with BleakClient(address, loop=loop) as client:
x = await client.is_connected()
print("Connected: {0}".format(x))
if __name__ == "__main__":
address = "F8:F0:05:F4:C5:B4"
loop = asyncio.get_event_loop()
loop.run_until_complete(run(address, loop))
But discover()
works well though.
What I’m doing
I created a small benchmark, who launch X times this program and display success/total attempts
:
import asyncio, bleak
async def run(address, loop, debug=False):
try:
async with bleak.BleakClient(address, loop=loop) as client:
x = await client.is_connected(timeout=5)
print(" V", end="", flush=True)
return True
except Exception as e:
print(" X", end="", flush=True)
return False
if __name__ == "__main__":
success = 0
address = "MAC ADDR"
for i in range(0, 10000):
loop = asyncio.get_event_loop()
if loop.run_until_complete(run(address, loop)):
success += 1
print("\033[K\r" + str(success) + "/" + str(i + 1), sep=" ", end="", flush=True)
# \033[K erase the line & \r return to the first char of the line
Current status:
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Troubleshooting — bleak 0.20.0a1 documentation
If you're having difficulty connecting to multiple devices, try to do a scan first and pass the returned BLEDevice objects to BleakClient calls....
Read more >Bleak device cant be found on connect but on scan
Hello i need a little help, im running a raspberry 4 (Ubuntu) with a Logilink BT Stick. BlueZ is Version: 5.56-0ubuntu4.2.
Read more >bleak 0.10.0 - PyPI
NET BleakClient connection. BleakClient in .NET backend will reuse previous device information when reconnecting so that it doesn't have to scan/discover again.
Read more >Python Tutorial 1: Connect BLE : Open GoPro - GitHub Pages
The Bleak BLE controller does not currently support autonomous pairing for the BlueZ backend. So if you are using BlueZ (i.e. Ubuntu, ...
Read more >How to Send Data between PC and Arduino using Bluetooth ...
A how-to guide on connecting your PC to an Arduino using Bluetooth LE and Python. To make it easier, we will use bleak...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m on my personal computer right now (xubuntu 18.04 too), I have BlueZ 5.48 and here’s my adapter:
I’m able to discover some bluetooth devices, as well as using bleak:
(using
scan on
frombluetoothctl
)(using bleak on an app)
I updated BlueZ to 5.50, and it’s working fine too (using bluetoothctl and Bleak):
I will close this issue and hope that the proposed solution above works.