micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

Unexpectedly, notify method ask for a connection argument

Open pidou46 opened this issue 2 years ago • 3 comments

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 ?

pidou46 avatar Sep 01 '23 14:09 pidou46

@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 https://github.com/micropython/micropython-lib/pull/728 to fix the documentation (and add a few more things).

jimmo avatar Sep 14 '23 03:09 jimmo

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

pidou46 avatar Sep 14 '23 13:09 pidou46

@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

jimmo avatar Sep 14 '23 14:09 jimmo