Replies: 3 comments 1 reply
-
First of all, you should not use any mutex. Or at least, I do not think that you need them and that you are better off without them in this case. But yes, connecting simultaneously to multiple clients is definitely possible: e.g. take a look at the two_devices.py example. My recommended way is to keep clients separate in different coroutines, but there are other ways to do it as well; look in previous (closed) issues regarding multiple clients.
In |
Beta Was this translation helpful? Give feedback.
-
Maybe I didn't understand well how the From the bluetooth documentation it seems the theorical number of "clients" is 7 (8 with the one communicating). But in practice with BLE people seems to say 3-4 sounds like the maximum. So if I don't put any locker/mutex to connect/communicate/disconnect, what would happen? How does Bleak manage it if I try to have more than 7 remote connected devices?
Indeed, I was just refering to the specific case when the connection to each device would be long-living (hours or so), so the Thank you, Note: will dig in previous issues even if I probably saw them ^^ |
Beta Was this translation helpful? Give feedback.
-
I have never connected to more than two simultaneously with Bleak, but theoretically it should work with more. There are some different limitations in different OS:es, but I am not sure the exact numbers or recommendations.
It registers callbacks on separate connection objects received from the OS BLE APIs. All connected devices are kept separate by the OS and Bleak utilizes that separation. If you are really interested in how it is done, read the source code. What happens if you have to many? No idea. Find out and document it here! |
Beta Was this translation helpful? Give feedback.
-
Description
Hi,
I'm really new in the BLE area but read a bunch of forums about how to do the right things but things are still unclear and it seems it could depend on the library but also the underlying BLE device used (which seems logic :) ).
My context:
After searching a few days it seems there is no trivial way to do some "request/response" in a synchronous way like we could do with HTTP call or anything else. I found 2 ways:
First
await write_gatt_char(...)
await sleep(...)
(the time to wait depends on how long the command could take at maximum on the (B) devices)await read_gatt_char(...)
What I don't like with this one is I need to guess a time to wait before reading the answer.
Second
Source: from @hbldh #59 (comment)
In this example, contrary to the first one, the callback will be triggered as soon as the device has sent it. So we do not wait for reading, it's immediate.
The example just uses a
sleep()
to make sure we handle notifications for at least the right time. I guess that if I have a long-running BLE client, I could not stop handling notifications (except when terminating the process), so thesleep()
would be useless:Question
What way do you recommend? Maybe a third one exists?
Also, since (A) should reach multiple (B) devices, is it possible with
bleak
to maintain all the BLE clients connected? Does the library manage it correctly under the hood (no conflict...)? Because my "asyncio mono-thread" during anawait
could run another write/read operation on another device. So should I use a mutex/lock wrapping all operations like this:Sorry for all the text, really glad to start using BLE and
bleak
👍Thank you,
Beta Was this translation helpful? Give feedback.
All reactions