ESPHome 2025.12.2
Loading...
Searching...
No Matches
ble_client.h
Go to the documentation of this file.
1#pragma once
2
7
8#ifdef USE_ESP32
9
10#include <esp_bt_defs.h>
11#include <esp_gap_ble_api.h>
12#include <esp_gatt_common_api.h>
13#include <esp_gattc_api.h>
14#include <array>
15#include <string>
16#include <vector>
17
18namespace esphome::ble_client {
19
21
22using namespace esp32_ble_client;
23
24class BLEClient;
25
27 public:
28 virtual void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
29 esp_ble_gattc_cb_param_t *param){};
30 virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {}
31 virtual void loop() {}
32 void set_address(uint64_t address) { address_ = address; }
34 // This should be transitioned to Established once the node no longer needs
35 // the services/descriptors/characteristics of the parent client. This will
36 // allow some memory to be freed.
38
39 BLEClient *parent() { return this->parent_; }
41
42 protected:
44 uint64_t address_;
45};
46
47class BLEClient : public BLEClientBase {
48 public:
49 void setup() override;
50 void dump_config() override;
51 void loop() override;
52
53 bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
54 esp_ble_gattc_cb_param_t *param) override;
55
56 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
57 bool parse_device(const espbt::ESPBTDevice &device) override;
58
59 void set_enabled(bool enabled);
60
62 node->client = this;
63 node->set_ble_client_parent(this);
64 this->nodes_.push_back(node);
65 }
66
67 bool enabled;
68
69 void set_state(espbt::ClientState state) override;
70
71 protected:
73
74 std::vector<BLEClientNode *> nodes_;
75};
76
77} // namespace esphome::ble_client
78
79#endif
uint8_t address
Definition bl0906.h:4
bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void register_ble_node(BLEClientNode *node)
Definition ble_client.h:61
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)
espbt::ESPBTClient * client
Definition ble_client.h:33
void set_ble_client_parent(BLEClient *parent)
Definition ble_client.h:40
virtual void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param)
Definition ble_client.h:28
virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
Definition ble_client.h:30
void set_address(uint64_t address)
Definition ble_client.h:32