ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
ble_client.cpp
Go to the documentation of this file.
1#include "ble_client.h"
6#include "esphome/core/log.h"
7
8#ifdef USE_ESP32
9
10namespace esphome::ble_client {
11
12static const char *const TAG = "ble_client";
13
16 this->enabled = true;
17}
18
21 for (auto *node : this->nodes_)
22 node->loop();
23}
24
26 ESP_LOGCONFIG(TAG, "BLE Client:");
28}
29
31 if (!this->enabled)
32 return false;
33 return BLEClientBase::parse_device(device);
34}
35
36void BLEClient::set_enabled(bool enabled) {
37 if (enabled == this->enabled)
38 return;
39 this->enabled = enabled;
40 if (!enabled) {
41 ESP_LOGI(TAG, "[%s] Disabling BLE client.", this->address_str());
42 this->disconnect();
43 }
44}
45
46bool BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t esp_gattc_if,
47 esp_ble_gattc_cb_param_t *param) {
48 if (!BLEClientBase::gattc_event_handler(event, esp_gattc_if, param))
49 return false;
50
51 for (auto *node : this->nodes_)
52 node->gattc_event_handler(event, esp_gattc_if, param);
53
54 if (!this->services_.empty() && this->all_nodes_established_()) {
55 this->release_services();
56 ESP_LOGD(TAG, "All clients established, services released");
57 }
58 return true;
59}
60
61void BLEClient::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
63
64 for (auto *node : this->nodes_)
65 node->gap_event_handler(event, param);
66}
67
70 for (auto &node : nodes_)
71 node->node_state = state;
72}
73
75 if (this->state() != espbt::ClientState::ESTABLISHED)
76 return false;
77 for (auto &node : nodes_) {
78 if (node->node_state != espbt::ClientState::ESTABLISHED)
79 return false;
80 }
81 return true;
82}
83
84} // namespace esphome::ble_client
85
86#endif
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
bool parse_device(const espbt::ESPBTDevice &device) override
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
void set_state(espbt::ClientState state) override
std::vector< BLEClientNode * > nodes_
Definition ble_client.h:74
void set_enabled(bool enabled)
std::vector< BLEService * > services_
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
void set_state(espbt::ClientState st) override
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
bool parse_device(const espbt::ESPBTDevice &device) override
bool state
Definition fan.h:0