pybricks / support

Pybricks support and general discussion
MIT License
106 stars 6 forks source link

[Bug] Bluetooth may remain disabled after running short program #1667

Open laurensvalk opened 2 months ago

laurensvalk commented 2 months ago

Describe the bug While working on https://github.com/pybricks/pybricks-micropython/pull/247#issuecomment-2152262496 I noticed that sometimes Bluetooth would not come back on on Prime Hub.

It turns out this was already the case in the stable firmware such as 3.5.0.

This isn't entirely an edge case, either. Sometimes an offline program will fail due to an immediate exception such as a motor not being plugged in. When connecting to fix the issue, sometimes the hub won't appear in Pybricks Code.

To reproduce

# comment
# The main program starts here.

Keep an eye on the Chrome scan window, or keep NRF connect open and occasionally refresh.

The hub will appear in a connectable state (blinking), but not advertise.

Expected behavior Work normally.

Screenshots There is a saying that a picture is worth a 1000 words. Screenshots really help to identify and solve problems.

Additional context

Since it's so rare, it's been hard to identify for sure, but I think this is where it gets stuck in pbsys/bluetooth:

        // reset Bluetooth chip
        pbsys_status_light_bluetooth_set_color(PBIO_COLOR_GREEN); // debug light
        pbdrv_bluetooth_power_on(false);
        PROCESS_WAIT_WHILE(pbdrv_bluetooth_is_ready());             // light can get stuck staying green
        pbsys_status_light_bluetooth_set_color(PBIO_COLOR_RED); // debug light

Now that we know this easier reproduction scenario, maybe we can find out for sure.

laurensvalk commented 2 months ago

Waiting a while and pressing the start button a few times again later seems to get it out of that state. Maybe some broadcast event gets it unstuck? (Possibly, yes: status change or program start/stop broadcasts an event).