Skip to content

espressif: _bleio: end connect() when the link fails before it is reported - #11859

Merged
tannewt merged 2 commits into
adafruit:mainfrom
urfdvw:espressif-bleio-connect-disconnect
Nov 18, 2026
Merged

tannewt merged 2 commits into
adafruit:mainfrom
urfdvw:espressif-bleio-connect-disconnect

Conversation

@urfdvw

@urfdvw urfdvw commented Nov 13, 2026 •

Copy link
Copy Markdown

NimBLE reports a central connection with BLE_GAP_EVENT_CONNECT only after it has read the peer's features and version. If the link fails with HCI 0x3E (connection failed to be established) before then, NimBLE retries it (BT_NIMBLE_ENABLE_CONN_REATTEMPT, on by default) and finally sends BLE_GAP_EVENT_DISCONNECT to the connect callback. No BLE_GAP_EVENT_CONNECT follows, and the connect timer was already cancelled when the controller reported the link, so connect() waited forever.

Handle BLE_GAP_EVENT_DISCONNECT in _connect_event by ending the wait with the disconnect reason, so connect() raises instead of hanging. With CIRCUITPY_VERBOSE_BLE, also print the reattempts and the reason.

Claude-Session: https://claude.ai/code/session_01619FtugLCtyvd5FEfJCyzo

Tested with this board: Guition JC3636W518C V2 (ESP32-S3R8), using an out-of-tree board definition: https://github.com/urfdvw/cpy-JC3636W518C


…orted

NimBLE reports a central connection with BLE_GAP_EVENT_CONNECT only after
it has read the peer's features and version. If the link fails with HCI
0x3E (connection failed to be established) before then, NimBLE retries it
(BT_NIMBLE_ENABLE_CONN_REATTEMPT, on by default) and finally sends
BLE_GAP_EVENT_DISCONNECT to the connect callback. No BLE_GAP_EVENT_CONNECT
follows, and the connect timer was already cancelled when the controller
reported the link, so connect() waited forever.

Handle BLE_GAP_EVENT_DISCONNECT in _connect_event by ending the wait with
the disconnect reason, so connect() raises instead of hanging. With
CIRCUITPY_VERBOSE_BLE, also print the reattempts and the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01619FtugLCtyvd5FEfJCyzo
@tannewt

tannewt commented Nov 13, 2026

Copy link
Copy Markdown
Member

Code looks ok. Why draft?

@urfdvw

urfdvw commented Nov 13, 2026

Copy link
Copy Markdown
Author

Code looks ok. Why draft?

Thanks, just wanted to add more concrete test details before getting people's attention.

@tannewt

tannewt commented Nov 16, 2026

Copy link
Copy Markdown
Member

Ok @urfdvw mention me when you are ready for a review.

@urfdvw
urfdvw marked this pull request as ready for review November 18, 2026 02:41
@urfdvw

urfdvw commented Nov 18, 2026 •

Copy link
Copy Markdown
Author

urfdvw/cpy-JC3636W518C#1
is how I tested it on ESP32 S3
can connect to my clicks powerkey board

The repo link above is now open for public access

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt
tannewt merged commit 2b61754 into adafruit:main Nov 18, 2026
13 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