ESPHome 2025.5.0
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 {
11namespace ble_client {
12
13static const char *const TAG = "ble_client";
14
17 this->enabled = true;
18}
19
22 for (auto *node : this->nodes_)
23 node->loop();
24}
25
27 ESP_LOGCONFIG(TAG, "BLE Client:");
29}
30
32 if (!this->enabled)
33 return false;
34 return BLEClientBase::parse_device(device);
35}
36
37void BLEClient::set_enabled(bool enabled) {
38 if (enabled == this->enabled)
39 return;
40 this->enabled = enabled;
41 if (!enabled) {
42 ESP_LOGI(TAG, "[%s] Disabling BLE client.", this->address_str().c_str());
43 this->disconnect();
44 }
45}
46
47bool BLEClient::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t esp_gattc_if,
48 esp_ble_gattc_cb_param_t *param) {
49 if (!BLEClientBase::gattc_event_handler(event, esp_gattc_if, param))
50 return false;
51
52 for (auto *node : this->nodes_)
53 node->gattc_event_handler(event, esp_gattc_if, param);
54
55 if (!this->services_.empty() && this->all_nodes_established_()) {
56 this->release_services();
57 ESP_LOGD(TAG, "All clients established, services released");
58 }
59 return true;
60}
61
62void BLEClient::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {
64
65 for (auto *node : this->nodes_)
66 node->gap_event_handler(event, param);
67}
68
70 BLEClientBase::set_state(state);
71 for (auto &node : nodes_)
72 node->node_state = state;
73}
74
76 if (this->state() != espbt::ClientState::ESTABLISHED)
77 return false;
78 for (auto &node : nodes_) {
79 if (node->node_state != espbt::ClientState::ESTABLISHED)
80 return false;
81 }
82 return true;
83}
84
85} // namespace ble_client
86} // namespace esphome
87
88#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:75
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
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
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7