Skip to content

AIOBLE notified() return None value when the peripheral is sending notificaiton values #453

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

Closed
steveli777 opened this issue Oct 1, 2021 · 2 comments

Comments

@steveli777
Copy link

PROBLEM:
I have a peripheral that sending the notification value constantly, and no None value. But when I invoke the characterisitc.notified() method, I got an None value.
BACKGROUND:
The peripheral will send the notify event per 1 second.
During testing, the connection keeps alive.
TEST CODE:
data = await characteristic.notified() print(data) await asyncio.sleep_ms(2000) data = await characteristic.notified() print(data) data = await characteristic.notified() print(data) data = await characteristic.notified() print(data)
RESULT:
b'\n\x00' b'\x14\x00' None b'\xb\x00'
ANALYSIS:
WHY here is a None return from notified()?
The key part is on "await asyncio.sleep_ms(2000) "after first notified().
I checked the code in client.py

  1. When sleeping, notify events are still coming, so line 357 is still setting value to characteristc._notify_data, and line 360 is still set the notify event.
  2. When second notified() be invoked, in line 343, self._notify_data is not None(the data is front previous notify event), so it return immediately.
  3. When third notified() be invoked, line 343, self._notify_data is None (it is consumed by step 2), then it jumps to the notify_event, but because the last notify_event is set in step 1, so in line 347, it return immediately without waiting for the REAL notify event, and the return data = None.
    image (2)
@jimmo
Copy link
Member

jimmo commented Nov 8, 2021

Thanks for the report @steve1aa -- please see #459 for a fix.

jimmo added a commit to jimmo/micropython-lib that referenced this issue Nov 10, 2021
This replicates the failure described in micropython#453 (which is fixed by micropython#459.

Also adds a test for subscription.

Signed-off-by: Jim Mussared <[email protected]>
jimmo added a commit to jimmo/micropython-lib that referenced this issue Nov 10, 2021
This replicates the failure described in micropython#453 (which is fixed by micropython#459.

Also adds a test for subscription.

Signed-off-by: Jim Mussared <[email protected]>
@dpgeorge
Copy link
Member

Fixed by dc03b4a

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

3 participants