12 namespace ble_client {
18 esp_ble_gattc_cb_param_t *param)
override {
19 if (event == ESP_GATTC_SEARCH_CMPL_EVT) {
20 this->
node_state = espbt::ClientState::ESTABLISHED;
31 esp_ble_gattc_cb_param_t *param)
override {
32 if (event == ESP_GATTC_DISCONNECT_EVT &&
33 memcmp(param->disconnect.remote_bda, this->parent_->get_remote_bda(), 6) == 0)
35 if (event == ESP_GATTC_SEARCH_CMPL_EVT)
36 this->
node_state = espbt::ClientState::ESTABLISHED;
44 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
override {
45 if (event == ESP_GAP_BLE_PASSKEY_REQ_EVT &&
46 memcmp(param->ble_security.auth_cmpl.bd_addr, this->parent_->get_remote_bda(), 6) == 0) {
56 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
override {
57 if (event == ESP_GAP_BLE_PASSKEY_NOTIF_EVT &&
58 memcmp(param->ble_security.auth_cmpl.bd_addr, this->parent_->get_remote_bda(), 6) == 0) {
59 uint32_t passkey = param->ble_security.key_notif.passkey;
69 void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
override {
70 if (event == ESP_GAP_BLE_NC_REQ_EVT &&
71 memcmp(param->ble_security.auth_cmpl.bd_addr, this->parent_->get_remote_bda(), 6) == 0) {
72 uint32_t passkey = param->ble_security.key_notif.passkey;
82 ble_client_ = ble_client;
86 void write(
const std::vector<uint8_t> &value);
97 esp_ble_gattc_cb_param_t *param)
override;
101 int ble_char_handle_ = 0;
102 esp_gatt_char_prop_t char_props_;
112 if (has_simple_value_) {
113 return write(this->value_simple_);
115 return write(this->value_template_(
x...));
120 this->value_template_ = std::move(func);
121 has_simple_value_ =
false;
125 this->value_simple_ = value;
126 has_simple_value_ =
true;
130 bool has_simple_value_ =
true;
131 std::vector<uint8_t> value_simple_;
132 std::function<std::vector<uint8_t>(Ts...)> value_template_{};
141 if (has_simple_value_) {
142 passkey = this->value_simple_;
144 passkey = this->value_template_(
x...);
146 if (passkey > 999999)
148 esp_bd_addr_t remote_bda;
150 esp_ble_passkey_reply(remote_bda,
true, passkey);
154 this->value_template_ = std::move(func);
155 has_simple_value_ =
false;
159 this->value_simple_ = value;
160 has_simple_value_ =
true;
165 bool has_simple_value_ =
true;
166 uint32_t value_simple_{0};
167 std::function<uint32_t(Ts...)> value_template_{};
175 esp_bd_addr_t remote_bda;
177 if (has_simple_value_) {
178 esp_ble_confirm_reply(remote_bda, this->value_simple_);
180 esp_ble_confirm_reply(remote_bda, this->value_template_(
x...));
185 this->value_template_ = std::move(func);
186 has_simple_value_ =
false;
190 this->value_simple_ = value;
191 has_simple_value_ =
true;
196 bool has_simple_value_ =
true;
197 bool value_simple_{
false};
198 std::function<bool(Ts...)> value_template_{};
206 esp_bd_addr_t remote_bda;
208 esp_ble_remove_bond_device(remote_bda);
BLEClientNumericComparisonReplyAction(BLEClient *ble_client)
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
BLEClientPasskeyNotificationTrigger(BLEClient *parent)
BLEClientRemoveBondAction(BLEClient *ble_client)
void set_value_simple(const bool &value)
uint8_t * get_remote_bda()
BLEClientPasskeyRequestTrigger(BLEClient *parent)
void set_value_simple(const std::vector< uint8_t > &value)
void set_value_simple(const uint32_t &value)
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
BLEClientConnectTrigger(BLEClient *parent)
void set_char_uuid32(uint32_t uuid)
void play(Ts... x) override
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
void play(Ts... x) override
void set_value_template(std::function< std::vector< uint8_t >(Ts...)> func)
BLEClientDisconnectTrigger(BLEClient *parent)
void set_value_template(std::function< uint32_t(Ts...)> func)
BLEClientNumericComparisonRequestTrigger(BLEClient *parent)
static ESPBTUUID from_uint32(uint32_t uuid)
void set_service_uuid16(uint16_t uuid)
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) override
static ESPBTUUID from_uint16(uint16_t uuid)
void play(Ts... x) override
void set_char_uuid16(uint16_t uuid)
void set_char_uuid128(uint8_t *uuid)
BLEWriterClientNode(BLEClient *ble_client)
void register_ble_node(BLEClientNode *node)
Implementation of SPI Controller mode.
static ESPBTUUID from_raw(const uint8_t *data)
void set_service_uuid32(uint32_t uuid)
void play(Ts... x) override
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
void set_service_uuid128(uint8_t *uuid)
BLEClientWriteAction(BLEClient *ble_client)
BLEClientPasskeyReplyAction(BLEClient *ble_client)
void set_value_template(std::function< bool(Ts...)> func)
espbt::ClientState node_state