Skip to content

Conversation

@laurensvalk
Copy link
Member

Adds a generic way to forcefully stop trying to run Bluetooth functions when the Bluetooth drivers get stuck. Such as mechanism had not yet been implemented after overhauling the Bluetooth drivers.

Before, we used to try to disconnect and stop observing/scanning in the MicroPython deinit, and stop waiting in case of a shutdown request. Now we do it as part of the pbio cleanup, and enforce shutdown if it fails since this is not a recoverable state.

In practice, this was mostly happening on Technic Hub. This was when it would be stuck in a blinking state if an advertising function got stuck.

This commit was tested by adding the following intentional obstacle in one of the Bluetooth functions.

 pbio_error_t pbdrv_bluetooth_peripheral_disconnect_func(pbio_os_state_t *state, void *context) {
 
+    static pbio_os_timer_t timer;
+
     PBIO_OS_ASYNC_BEGIN(state);
 
+    while (true) {
+        PBIO_OS_AWAIT_MS(state, &timer, 1000);
+    }

This would cause the de-initialization to never complete if a peripheral is connected. With this commit, it will exit the task and proceed to normal shutdown.

It will still save the user program and data, etc.

Such as mechanism had not yet been implemented after overhauling the Bluetooth drivers.

Before, we used to try to disconnect and stop observing/scanning in the MicroPython deinit, and stop waiting in case of a shutdown request.

No we do it as part of the pbio cleanup, and enforce shutdown if it fails since this is not a recoverable state.
@coveralls
Copy link

Coverage Status

coverage: 59.942% (-0.1%) from 60.042%
when pulling 8b576b3 on work
into a67ce01 on master.

@laurensvalk laurensvalk merged commit 8b576b3 into master Sep 30, 2025
32 checks passed
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

Successfully merging this pull request may close these issues.

3 participants