Hello,
I’m trying to connect from a Windows 11 PC to a u‑blox ANNA‑B412 peripheral using Bleak (WinRT backend). The device is discovered correctly, client.is_connected becomes True right after connect(), but within ~0.2–2 seconds the GATT session is closed and client.is_connected becomes False.
Environment
- OS: Windows 11
- BLE peripheral: u‑blox ANNA‑B412
- Bleak version: 3.0.0
Expected behavior
await client.connect() should keep the connection stable (at least a few seconds)
client.is_connected should remain True
Actual behavior
GattSessionStatus becomes ACTIVE then quickly switches to CLOSED
client.is_connected becomes False shortly after connecting
- In Wireshark HCI logs, a Disconnect Complete appears with reason 0x3E (Connection Failed to be Established)
Bleak logs (WinRT)
2026-05-19 12:04:20,857 | DEBUG | bleak.backends.winrt.scanner | 20 devices found. Watcher status: <BluetoothLEAdvertisementWatcherStatus.STOPPED: 3>.
2026-05-19 12:04:20,859 | DEBUG | bleak.backends.winrt.client | Connecting to BLE device @ ******
2026-05-19 12:04:21,089 | DEBUG | bleak.backends.winrt.client | getting services (service_cache_mode=<BluetoothCacheMode.CACHED: 0>, cache_mode=<BluetoothCacheMode.CACHED: 0>)...
2026-05-19 12:04:21,347 | DEBUG | bleak.backends.winrt.client | session_status_changed_event_handler: id: BluetoothLE#BluetoothLE , error: <BluetoothError.SUCCESS: 0>, status: <GattSessionStatus.ACTIVE: 1>
2026-05-19 12:04:21,359 | INFO | APP | Connect� en 1.145 s
2026-05-19 12:04:21,599 | DEBUG | bleak.backends.winrt.client | session_status_changed_event_handler: id: BluetoothLE#BluetoothLE , error: <BluetoothError.SUCCESS: 0>, status: <GattSessionStatus.CLOSED: 0>
2026-05-19 12:04:21,602 | DEBUG | bleak.backends.winrt.client | closing requester
2026-05-19 12:04:21,606 | DEBUG | bleak.backends.winrt.client | closing session
2026-05-19 12:04:22,358 | ERROR | APP | ========== EXCEPTION ==========
2026-05-19 12:04:22,358 | ERROR | APP | [CONNECT ERROR] attempt=1
2026-05-19 12:04:22,358 | ERROR | APP | Type : RuntimeError
2026-05-19 12:04:22,360 | ERROR | APP | Message :Client disconnect after connect
2026-05-19 12:04:22,364 | ERROR | APP | Traceback:
Traceback (most recent call last):
File "****\code.py", line 133, in _connect_with_policy
raise RuntimeError("Client disconnect after connect")
RuntimeError: Client disconnect after connect
2026-05-19 12:04:22,366 | ERROR | APP | ==============================
Minimal code
async def _connect_with_policy(self):
global DEBUG_FALSE
last_err = None
total_time = 0.0
for attempt in range(1, self.max_attempts + 1):
t0 = time.perf_counter()
client = BleakClient(self.address, timeout=self.connect_timeout_s,winrt={"use_cached_services": True})
try:
await client.connect()
conn_time = time.perf_counter() - t0
total_time += conn_time
logger.info(" Connecté en %.3f s", conn_time)
await asyncio.sleep(1)
if not client.is_connected:
raise RuntimeError("Client disconnect after connect")
return True, total_time, None, client
except Exception as e:
last_err = e
dump_exception(e, prefix=f"[CONNECT ERROR] attempt={attempt}")
await self._safe_disconnect(client)
DEBUG_FALSE=1
break #debug
if attempt < self.max_attempts:
delay = 1.5 * (2 ** (attempt - 1))
logger.warning("Retry après %.1f s", delay)
total_time += delay
await asyncio.sleep(delay)
continue
logger.error("ECHEC après %d tentatives", attempt)
return False, None, str(e), None
return False, None, str(last_err), None
Wireshark HCI observations (bad case)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 6 Sent Vendor Command 0x001E (opcode 0xFC1E)
controller host HCI_EVT 8 Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
host controller HCI_CMD 12 Sent LE Set Extended Scan Parameters
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Parameters)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 11 Sent LE Add Device To Filter Accept List
controller host HCI_EVT 7 Rcvd Command Complete (LE Add Device To Filter Accept List)
host controller HCI_CMD 26 Sent Vendor Command 0x001E (opcode 0xFC1E)
controller host HCI_EVT 9 Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
host controller HCI_CMD 12 Sent LE Set Extended Scan Parameters
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Parameters)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
controller host HCI_EVT 59 Rcvd LE Meta (LE Extended Advertising Report)
host controller HCI_CMD 30 Sent LE Extended Create Connection [v1]
controller host HCI_EVT 7 Rcvd Command Status (LE Extended Create Connection [v1])
controller host HCI_EVT 34 Rcvd LE Meta (LE Enhanced Connection Complete [v1])
host controller HCI_CMD 6 Sent LE Read Channel Map
controller host HCI_EVT 36 Rcvd Vendor-Specific
controller host HCI_EVT 14 Rcvd Command Complete (LE Read Channel Map)
host controller HCI_CMD 32 Sent LE Enable Encryption
controller host HCI_EVT 7 Rcvd Command Status (LE Enable Encryption)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 11 Sent LE Remove Device From Filter Accept List
controller host HCI_EVT 7 Rcvd Command Complete (LE Remove Device From Filter Accept List)
host controller HCI_CMD 6 Sent Vendor Command 0x001E (opcode 0xFC1E)
controller host HCI_EVT 8 Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
host controller HCI_CMD 12 Sent LE Set Extended Scan Parameters
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Parameters)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
controller host HCI_EVT 7 Rcvd Disconnect Complete
with
Bluetooth HCI Event - Disconnect Complete
Event Code: Disconnect Complete (0x05)
Parameter Total Length: 4
Status: Success (0x00)
Connection Handle: 0x0800
Reason: Connection Failed to be Established (0x3e)
Wireshark “good case”
Sometimes the connection proceeds further:
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 6 Sent Vendor Command 0x001E (opcode 0xFC1E)
controller host HCI_EVT 8 Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
host controller HCI_CMD 12 Sent LE Set Extended Scan Parameters
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Parameters)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 11 Sent LE Add Device To Filter Accept List
controller host HCI_EVT 7 Rcvd Command Complete (LE Add Device To Filter Accept List)
host controller HCI_CMD 26 Sent Vendor Command 0x001E (opcode 0xFC1E)
controller host HCI_EVT 9 Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
host controller HCI_CMD 12 Sent LE Set Extended Scan Parameters
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Parameters)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
controller host HCI_EVT 59 Rcvd LE Meta (LE Extended Advertising Report)
host controller HCI_CMD 30 Sent LE Extended Create Connection [v1]
controller host HCI_EVT 7 Rcvd Command Status (LE Extended Create Connection [v1])
controller host HCI_EVT 34 Rcvd LE Meta (LE Enhanced Connection Complete [v1])
host controller HCI_CMD 6 Sent LE Read Channel Map
controller host HCI_EVT 36 Rcvd Vendor-Specific
controller host HCI_EVT 14 Rcvd Command Complete (LE Read Channel Map)
host controller HCI_CMD 32 Sent LE Enable Encryption
controller host HCI_EVT 7 Rcvd Command Status (LE Enable Encryption)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
host controller HCI_CMD 11 Sent LE Remove Device From Filter Accept List
controller host HCI_EVT 7 Rcvd Command Complete (LE Remove Device From Filter Accept List)
host controller HCI_CMD 6 Sent Vendor Command 0x001E (opcode 0xFC1E)
controller host HCI_EVT 8 Rcvd Command Complete (Vendor Command 0x001E [opcode 0xFC1E])
host controller HCI_CMD 12 Sent LE Set Extended Scan Parameters
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Parameters)
host controller HCI_CMD 10 Sent LE Set Extended Scan Enable
controller host HCI_EVT 7 Rcvd Command Complete (LE Set Extended Scan Enable)
ublox_0f:27:c3 (ANNA-B4-0F27C3) localhost () SMP 11 Rcvd Security Request: AuthReq: Bonding
controller host HCI_EVT 7 Rcvd Encryption Change [v1]
localhost () ublox_0f:27:c3 (ANNA-B4-0F27C3) ATT 12 Sent Exchange MTU Request, Client Rx MTU: 527
controller host HCI_EVT 8 Rcvd Number of Completed Packets
controller host HCI_EVT 14 Rcvd LE Meta (LE Data Length Change)
ublox_0f:27:c3 (ANNA-B4-0F27C3) localhost () ATT 12 Rcvd Exchange MTU Response, Server Rx MTU: 247
localhost () ublox_0f:27:c3 (ANNA-B4-0F27C3) ATT 14 Sent Write Request, Handle: 0x001a (Unknown)
controller host HCI_EVT 8 Rcvd Number of Completed Packets
ublox_0f:27:c3 (ANNA-B4-0F27C3) localhost () ATT 10 Rcvd Write Response, Handle: 0x001a (Unknown)
localhost () ublox_0f:27:c3 (ANNA-B4-0F27C3) ATT 19 Sent Write Command, Handle: 0x0019 (Unknown)
ublox_0f:27:c3 (ANNA-B4-0F27C3) localhost () ATT 19 Rcvd Handle Value Notification, Handle: 0x0019 (Unknown)
controller host HCI_EVT 9 Rcvd LE Meta (LE PHY Update Complete)
controller host HCI_EVT 8 Rcvd Number of Completed Packets
ublox_0f:27:c3 (ANNA-B4-0F27C3) localhost () ATT 29 Rcvd Handle Value Notification, Handle: 0x0019 (Unknown)
localhost () ublox_0f:27:c3 (ANNA-B4-0F27C3) ATT 14 Sent Write Command, Handle: 0x0019 (Unknown)
localhost () ublox_0f:27:c3 (ANNA-B4-0F27C3) ATT 14 Sent Write Command, Handle: 0x0019 (Unknown)
localhost () ublox_0f:27:c3 (ANNA-B4-0F27C3) ATT 14 Sent Write Request, Handle: 0x001a (Unknown)
controller host HCI_EVT 8 Rcvd Number of Completed Packets
controller host HCI_EVT 8 Rcvd Number of Completed Packets
controller host HCI_EVT 8 Rcvd Number of Completed Packets
ublox_0f:27:c3 (ANNA-B4-0F27C3) localhost () ATT 10 Rcvd Write Response, Handle: 0x001a (Unknown)
host controller HCI_CMD 7 Sent Disconnect
controller host HCI_EVT 7 Rcvd Command Status (Disconnect)
controller host HCI_EVT 7 Rcvd Disconnect Complete
Questions
-
On Windows/WinRT, is it expected that a BLE connection briefly becomes ACTIVE and then immediately transitions to CLOSED, even though connect() returns successfully?
-
What could be the underlying reason for the controller terminating the connection with HCI error 0x3E ("Connection Failed to be Established") in this case, despite the connection being reported as established initially?
Thanks!
Hello,
I’m trying to connect from a Windows 11 PC to a u‑blox ANNA‑B412 peripheral using Bleak (WinRT backend). The device is discovered correctly,
client.is_connectedbecomesTrueright afterconnect(), but within ~0.2–2 seconds the GATT session is closed andclient.is_connectedbecomesFalse.Environment
Expected behavior
await client.connect()should keep the connection stable (at least a few seconds)client.is_connectedshould remainTrueActual behavior
GattSessionStatusbecomesACTIVEthen quickly switches toCLOSEDclient.is_connectedbecomesFalseshortly after connectingBleak logs (WinRT)
Minimal code
Wireshark HCI observations (bad case)
with
Wireshark “good case”
Sometimes the connection proceeds further:
Questions
On Windows/WinRT, is it expected that a BLE connection briefly becomes
ACTIVEand then immediately transitions toCLOSED, even thoughconnect()returns successfully?What could be the underlying reason for the controller terminating the connection with HCI error 0x3E ("Connection Failed to be Established") in this case, despite the connection being reported as established initially?
Thanks!