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

tempsensor.py example disconnects unexpectedly #807

Open
Remco-Schoeman opened this issue Feb 16, 2024 · 0 comments
Open

tempsensor.py example disconnects unexpectedly #807

Remco-Schoeman opened this issue Feb 16, 2024 · 0 comments

Comments

@Remco-Schoeman
Copy link

at the line below the example waits for the connected client to disconnect.
What is not obvious is that awaiting this disconnected() call causes an disconnect after 60 seconds!

It took me a long time reading code before I found the reason why: The timeout_ms parameter for the disconnected() call specifies a default timeout of 60 seconds for the wait, after which a CancelledError is raised, and the peripheral_task() exits, disconnecting the connection.

async def disconnected(self, timeout_ms=60000, disconnect=False):

regrettably neither the CancelledError or the stacktrace give any clear indication of what happened.

As this is example code it might be nice to change the example to this instead:

    print("Connection from", connection.device)
    while connection.is_connected():
        temp_characteristic.notify(connection)
        await asyncio.sleep_ms(5_000)

which will push change notifications to the connected client every 5 sec or so, and not disconnect mysteriously (for micropython noobs like me in any case) after 60 seconds.

I can make a PR for this if desired.

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

1 participant