From 8cfcd5904c7a3b88310227ce8947f0117627868c Mon Sep 17 00:00:00 2001 From: rbaron Date: Mon, 15 Aug 2022 05:09:33 +0200 Subject: [PATCH] Fixes BLE remote address type when connecting (#3702) --- esphome/components/ble_client/ble_client.cpp | 3 ++- esphome/components/ble_client/ble_client.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/components/ble_client/ble_client.cpp b/esphome/components/ble_client/ble_client.cpp index d06c3c4cad..5f58d8273f 100644 --- a/esphome/components/ble_client/ble_client.cpp +++ b/esphome/components/ble_client/ble_client.cpp @@ -54,6 +54,7 @@ bool BLEClient::parse_device(const espbt::ESPBTDevice &device) { this->remote_bda[3] = (addr >> 16) & 0xFF; this->remote_bda[4] = (addr >> 8) & 0xFF; this->remote_bda[5] = (addr >> 0) & 0xFF; + this->remote_addr_type = device.get_address_type(); return true; } @@ -83,7 +84,7 @@ void BLEClient::set_enabled(bool enabled) { void BLEClient::connect() { ESP_LOGI(TAG, "Attempting BLE connection to %s", this->address_str().c_str()); - auto ret = esp_ble_gattc_open(this->gattc_if, this->remote_bda, BLE_ADDR_TYPE_PUBLIC, true); + auto ret = esp_ble_gattc_open(this->gattc_if, this->remote_bda, this->remote_addr_type, true); if (ret) { ESP_LOGW(TAG, "esp_ble_gattc_open error, address=%s status=%d", this->address_str().c_str(), ret); this->set_states_(espbt::ClientState::IDLE); diff --git a/esphome/components/ble_client/ble_client.h b/esphome/components/ble_client/ble_client.h index b122bfd11e..5ed8f219d1 100644 --- a/esphome/components/ble_client/ble_client.h +++ b/esphome/components/ble_client/ble_client.h @@ -115,6 +115,7 @@ class BLEClient : public espbt::ESPBTClient, public Component { int gattc_if; esp_bd_addr_t remote_bda; + esp_ble_addr_type_t remote_addr_type; uint16_t conn_id; uint64_t address; bool enabled;