ESPHome 2025.5.0
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 {
19namespace ble_client {
20
22
23using namespace esp32_ble_client;
24
25class BLEClient;
26
28 public:
29 virtual void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
30 esp_ble_gattc_cb_param_t *param){};
31 virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) {}
32 virtual void loop() {}
33 void set_address(uint64_t address) { address_ = address; }
35 // This should be transitioned to Established once the node no longer needs
36 // the services/descriptors/characteristics of the parent client. This will
37 // allow some memory to be freed.
39
40 BLEClient *parent() { return this->parent_; }
42
43 protected:
45 uint64_t address_;
46};
47
48class BLEClient : public BLEClientBase {
49 public:
50 void setup() override;
51 void dump_config() override;
52 void loop() override;
53
54 bool gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
55 esp_ble_gattc_cb_param_t *param) override;
56
57 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override;
58 bool parse_device(const espbt::ESPBTDevice &device) override;
59
60 void set_enabled(bool enabled);
61
63 node->client = this;
64 node->set_ble_client_parent(this);
65 this->nodes_.push_back(node);
66 }
67
68 bool enabled;
69
70 void set_state(espbt::ClientState state) override;
71
72 protected:
74
75 std::vector<BLEClientNode *> nodes_;
76};
77
78} // namespace ble_client
79} // namespace esphome
80
81#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:62
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)
espbt::ESPBTClient * client
Definition ble_client.h:34
void set_ble_client_parent(BLEClient *parent)
Definition ble_client.h:41
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:29
virtual void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
Definition ble_client.h:31
void set_address(uint64_t address)
Definition ble_client.h:33
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7