diff --git a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp index 0e1a1002a3..9a3c18269a 100644 --- a/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +++ b/esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp @@ -11,6 +11,7 @@ #include #include #endif +#include #include #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #ifdef USE_OTA #include "esphome/components/ota/ota_backend.h" @@ -287,9 +289,21 @@ void ESP32BLETracker::register_listener(ble_device_base::ESPBTDeviceListener *li } void ESP32BLETracker::get_adapter_mac(uint8_t out[6]) { +#ifdef CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID + // Hosted controller (esp32-p4): the adapter MAC lives in the remote chip's + // efuse, so only the running stack knows it; ESP_MAC_BT does not exist + // here. Null before init becomes all-zero, the proxy's unavailable state. + const uint8_t *mac = esp_bt_dev_get_address(); + if (mac != nullptr) { + memcpy(out, mac, 6); + } else { + memset(out, 0, 6); + } +#else // IDF owns the BT-offset derivation (base + 2 with four universal MACs, // base + 1 with two); works before the BT stack is up. esp_read_mac(out, ESP_MAC_BT); +#endif } void ESP32BLETracker::register_listener(ESPBTDeviceListener *listener) {