Skip to content

Instability when exiting btstack run loop #1479

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
josh26turner opened this issue Aug 19, 2023 · 2 comments
Open

Instability when exiting btstack run loop #1479

josh26turner opened this issue Aug 19, 2023 · 2 comments
Assignees
Milestone

Comments

@josh26turner
Copy link

josh26turner commented Aug 19, 2023

I'm not sure if this issue should sit in this repo or BTStack repo.

I have an application for the Pico W that will periodically take a measurement and send the value over a Bluetooth notifcation to a connected device. As it's battery powered, after sending a notification, I run the function btstack_run_loop_trigger_exit(), and have a loop that looks (roughly) like this:

while (true) {
    printf("Starting btstack\n");
    btstack_run_loop_execute();
    printf("Exited btstack\n");

    printf("Sleeping for %ds\n", POST_MEASUREMENT_SLEEP_TIME_MS / 1000);
    sleep_ms(POST_MEASUREMENT_SLEEP_TIME_MS);

    // Less important, queuing up work for when btstack starts again
    if (le_notification_enabled)
    {
        btstack_run_loop_set_timer(&sensor_reading_timer, 0);
        btstack_run_loop_add_timer(&sensor_reading_timer);
    }
}

Which seems to work for the first few measurement, producing logs that look like this (the "Exiting btstack" log line is printed immediately before calling btstack_run_loop_trigger_exit()):

Starting btstack
BTstack up and running on 28:CD:C1:09:3E:D0.
Enabling notifications
Requesting reading
Sensor values read
Sending notification to connected device
Exiting btstack
Exited btstack
Sleeping for 10s
Starting btstack
Requesting reading
Sensor values read
Sending notification to connected device
Exiting btstack
Exited btstack
Sleeping for 10s
Starting btstack
Requesting reading
Sensor values read
Sending notification to connected device
Exiting btstack
Exited btstack

However, after a few successful attempts (not consistent in number), instead of continuing code following btstack_run_loop_execute(), the exit will jump back code when exiting the run loop. It starts with the line before and then immediately starts btstack again:

Starting btstack
Requesting reading
Sensor values read
Sending notification to connected device
Exiting btstack
Exited btstack
Sleeping for 10s
Requesting reading
Sensor values read
Sending notification to connected device
Exiting btstack
Starting btstack

You can see that immediately following the "Exiting btstack" log line is the line "Starting btstack". At which point the program hangs (as I haven't queued up any work for btstack to do).

If required, I can add some example code to run and replicate.

@peterharperuk
Copy link
Contributor

I think we'd need to see the full code. I don't think we expect the code to be used like that.

@peterharperuk
Copy link
Contributor

This might fix the problems stopping bluetooth #2446
I've pushed an example here which seems to work raspberrypi/pico-examples#644

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

No branches or pull requests

3 participants