36 esp_ble_gattc_cb_param_t *param) {
38 case ESP_GATTC_OPEN_EVT: {
39 if (param->open.status == ESP_GATT_OK) {
40 ESP_LOGI(TAG,
"[%s] Connected successfully!", this->
get_name().c_str());
45 case ESP_GATTC_CLOSE_EVT: {
50 case ESP_GATTC_SEARCH_CMPL_EVT: {
56 ESP_LOGW(TAG,
"No sensor characteristic found at service %s char %s", this->
service_uuid_.
to_string().c_str(),
57 this->char_uuid_.to_string().c_str());
62 auto *descr = chr->get_descriptor(this->
descr_uuid_);
63 if (descr ==
nullptr) {
66 ESP_LOGW(TAG,
"No sensor descriptor found at service %s char %s descr %s",
68 this->descr_uuid_.to_string().c_str());
71 this->
handle = descr->handle;
74 auto status = esp_ble_gattc_register_for_notify(this->
parent()->get_gattc_if(),
75 this->
parent()->get_remote_bda(), chr->handle);
77 ESP_LOGW(TAG,
"esp_ble_gattc_register_for_notify failed, status=%d",
status);
80 this->
node_state = espbt::ClientState::ESTABLISHED;
87 case ESP_GATTC_READ_CHAR_EVT: {
88 if (param->read.handle == this->handle) {
89 if (param->read.status != ESP_GATT_OK) {
90 ESP_LOGW(TAG,
"Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
98 case ESP_GATTC_NOTIFY_EVT: {
99 if (param->notify.handle != this->handle)
101 ESP_LOGV(TAG,
"[%s] ESP_GATTC_NOTIFY_EVT: handle=0x%x, value=0x%x", this->
get_name().c_str(),
102 param->notify.handle, param->notify.value[0]);
106 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
107 if (param->reg_for_notify.status == ESP_GATT_OK && param->reg_for_notify.handle == this->handle)
108 this->
node_state = espbt::ClientState::ESTABLISHED;
espbt::ESPBTUUID service_uuid_
espbt::ESPBTUUID char_uuid_
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
espbt::ESPBTUUID descr_uuid_
void dump_config() override
std::string parse_data(uint8_t *value, uint16_t value_len)
void publish_state(const std::string &state)