Conversation
Currently the notify subscription is wired only in ESP_GAP_BLE_AUTH_CMPL_EVT, after which get_characteristic() is called immediately. This is racy: on ESP-IDF 5.x the AUTH_CMPL event is occasionally delivered *before* SEARCH_CMPL on first connect (e.g. via a BLE proxy with cached service DB). When that happens get_characteristic() returns nullptr and we log 'No control service found at device, not a Daikin Madoka..?' even though the device is fine — the client just goes idle until the user reboots ESP32 or power-cycles the BRC1H. Track both events with bool flags (search_complete_, auth_complete_), trigger the register-for-notify path only when both are set. Reset the flags on DISCONNECT so a reconnect re-arms the handshake. The actual register logic is moved into try_register_notifications_() unchanged beyond that. Observed on two BRC1H controllers proxied through one m5stack-bleproxy.
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://Petapton/esphome@pull/12/head
components: [daikin_madoka]
refresh: 1h(Added by the PR bot) |
|
Hi, have you already triggered the race condition? In case, would you mind reporting steps to let me reproduce it? |
|
Yes — hit it repeatedly on cold boot. On my setup roughly 1 in 5 cold boots ended with the client idle and How to reproduce / catch it (Bluedroid, ESP-IDF 5.x)
On the ESP-IDF behavior (your second question): ESP-IDF gives no ordering guarantee between GATT service-discovery completion and GAP authentication completion — they are driven by separate event paths. The canonical I track both events ( |
Currently the notify subscription is wired only in
ESP_GAP_BLE_AUTH_CMPL_EVT, after whichget_characteristic()is called immediately. This is racy: on ESP-IDF 5.x theAUTH_CMPLevent is occasionally delivered beforeSEARCH_CMPLon first connect (e.g. via a BLE proxy with a cached service DB). When that happensget_characteristic()returnsnullptrand we log "No control service found at device, not a Daikin Madoka..?" even though the device is fine — the client just goes idle until the user reboots ESP32 or power-cycles the BRC1H.Track both events with
boolflags (search_complete_,auth_complete_), and trigger the register-for-notify path only when both are set. Reset the flags onDISCONNECTso a reconnect re-arms the handshake. The actual register logic is moved verbatim into a newtry_register_notifications_()helper.Independent of the other Madoka PRs in flight.
Test plan
disconnectbutton onble_client): on reconnect the handshake runs again — no "No control service found" misfire.