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

Wait notification functionality feature #1501

Open
vovagorodok opened this issue Feb 4, 2024 · 7 comments
Open

Wait notification functionality feature #1501

vovagorodok opened this issue Feb 4, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@vovagorodok
Copy link

Will be nice to have functionality like client.wait_for_notify() in order to have possibility to write simple scripts of serial communication that works like:

await client.wait_for_notify()
await client.read_gatt_char(tx_char)

I have this issue in my ArduinoBleOTA library for firmware uploading over ble:
https://github.com/vovagorodok/ArduinoBleOTA/blob/7fb9e079cf54e02b0701d117754e14ebe5db34cf/tools/uploader.py#L144

@dlech dlech added the enhancement New feature or request label Feb 4, 2024
@dlech
Copy link
Collaborator

dlech commented Feb 4, 2024

As a workaround, you could use an asyncio.Event(). The notification callback would need to call event.set(), then you would do:

await event.wait()
await client.read_gatt_char(tx_char)
event.clear()

@vovagorodok
Copy link
Author

As I see callback has bytearray as second argument. It means that value from characteristics is being read during callback and await client.read_gatt_char(tx_char) will read from characteristics second time?

@dlech
Copy link
Collaborator

dlech commented Feb 4, 2024

Based on your example, I thought that maybe you had a case where the value was too large to fit in a notification and you had to do a read to get the full value. But if you just want to use the value from the notification and not read again, then you can use asyncio.Queue() instead of asyncio.Event() and leave out the read.

@vovagorodok
Copy link
Author

Thanks! I will use asyncio.Queue() as solution. There are any plans to add method like client.wait_for_notify() or solution with asyncio.Queue() looks ok from Your PoV?

@dlech
Copy link
Collaborator

dlech commented Mar 13, 2024

No concrete plans. But having something that could be used in an async for loop like we did for advertisement data in #1361 could be nice.

@vovagorodok
Copy link
Author

Should we close this issue or hold in order to track progress?

@dlech
Copy link
Collaborator

dlech commented Mar 14, 2024

I don't see any duplicate issues, so let's leave this one open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants