1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-13 22:28:14 +00:00

Debug disconnecting before connected

This commit is contained in:
J. Nick Koston 2025-02-21 17:58:23 -06:00
parent c281351732
commit 3fcb676fef
No known key found for this signature in database
2 changed files with 8 additions and 1 deletions

View File

@ -125,6 +125,10 @@ esp_err_t BLEClientBase::pair() { return esp_ble_set_encryption(this->remote_bda
void BLEClientBase::disconnect() {
if (this->state_ == espbt::ClientState::IDLE || this->state_ == espbt::ClientState::DISCONNECTING)
return;
if (this->conn_id_ == UNSET_CONN_ID) {
ESP_LOGW(TAG, "[%d] [%s] Disconnecting before connected", this->connection_index_, this->address_str_.c_str());
return;
}
ESP_LOGI(TAG, "[%d] [%s] Disconnecting.", this->connection_index_, this->address_str_.c_str());
auto err = esp_ble_gattc_close(this->gattc_if_, this->conn_id_);
if (err != ESP_OK) {
@ -241,6 +245,7 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
this->log_event_("ESP_GATTC_CLOSE_EVT");
this->release_services();
this->set_state(espbt::ClientState::IDLE);
this->conn_id_ = UNSET_CONN_ID;
break;
}
case ESP_GATTC_SEARCH_RES_EVT: {

View File

@ -21,6 +21,8 @@ namespace esp32_ble_client {
namespace espbt = esphome::esp32_ble_tracker;
static const int UNSET_CONN_ID = 0xFFFF;
class BLEClientBase : public espbt::ESPBTClient, public Component {
public:
void setup() override;
@ -94,7 +96,7 @@ class BLEClientBase : public espbt::ESPBTClient, public Component {
int gattc_if_;
esp_bd_addr_t remote_bda_;
esp_ble_addr_type_t remote_addr_type_{BLE_ADDR_TYPE_PUBLIC};
uint16_t conn_id_{0xFFFF};
uint16_t conn_id_{UNSET_CONN_ID};
uint64_t address_{0};
bool auto_connect_{false};
std::string address_str_{};