Skip to content

Unexpectedly, notify method ask for a connection argument #721

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

Open
pidou46 opened this issue Sep 1, 2023 · 3 comments
Open

Unexpectedly, notify method ask for a connection argument #721

pidou46 opened this issue Sep 1, 2023 · 3 comments

Comments

@pidou46
Copy link

pidou46 commented Sep 1, 2023

Hello,

In the README.md:
https://github.com/micropython/micropython-lib/tree/master/micropython/bluetooth/aioble
it is stated that the notify method take one optional argument:

temp_char.notify(b'optional data')

but if I call it without any argument I get:

TypeError: function takes 2 positional arguments but 1 were given

In server.py the notify method take a connection object as 2nd argument:

def notify(self, connection, data=None):

server.py module wouldn't be able to get the conenction object internally ?

@jimmo
Copy link
Member

jimmo commented Sep 14, 2023

@pidou46 The documentation is incorrect. You must specify a connection, as the server might have multiple concurrent connections. If you want to automatically send to all connections, use subscription and char.write(..., send_update=True).

Created #728 to fix the documentation (and add a few more things).

@pidou46
Copy link
Author

pidou46 commented Sep 14, 2023

Thank @jimmo
Where do I get the connection handler? when registering service ?
If I understand correctly, register_services does not return anything

@jimmo
Copy link
Member

jimmo commented Sep 14, 2023

@pidou46 You get the connection object when something connects to you. See e.g. https://github.com/micropython/micropython-lib/blob/master/micropython/bluetooth/aioble/examples/temp_sensor.py#L57

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

No branches or pull requests

2 participants