pybricks / support

Pybricks support and general discussion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Bluetooth may remain disabled after running short program

laurensvalk opened this issue · comments

Describe the bug
While working on pybricks/pybricks-micropython#247 (comment) 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

  • Add the following empty program that does nothing.
# comment
# The main program starts here.
  • Disconnect from Pybricks Code
  • Hammer the start button a lot of times.

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.

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).