BleakClient: Timeout issue observed with BleakClient function #687
Answered
by
hbldh
RohanDicholkar
asked this question in
Q&A
-
I am trying to run a example code given on github to discover BLE devices and then get connected to my device. My sample code is as below. Performance of the code is very unstable. Out of about 10 tries, I am able to connect to my device only once for remaining 9 times I get timeout error. Timeout error is also given below, Can someone please suggest if any change is required in the program below. Is there any already known issue for this function """
Connect by BLEDevice
"""
import asyncio
import platform
import sys
from bleak import BleakClient, BleakScanner
from bleak.exc import BleakError
ADDRESS = (
"6E:01:8F:08:37:71"
if platform.system() != "Darwin"
else "B9EA5233-37EF-4DD6-87A8-2A875E821C46"
)
async def main(ble_address: str):
device = await BleakScanner.find_device_by_address(ble_address, timeout=5.0)
if not device:
raise BleakError(f"A device with address {ble_address} could not be found.")
async with BleakClient(device) as client:
svcs = await client.get_services()
print("Services:")
for service in svcs:
print(service)
if __name__ == "__main__":
asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS)) Timeout error
|
Beta Was this translation helpful? Give feedback.
Answered by
hbldh
Nov 26, 2021
Replies: 1 comment
-
Closing this in favour of the issue #688 that you created. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hbldh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Closing this in favour of the issue #688 that you created.