34 esp_ble_gattc_cb_param_t *param) {
36 case ESP_GATTC_OPEN_EVT: {
37 if (param->open.status == ESP_GATT_OK) {
38 ESP_LOGI(TAG,
"[%s] Connected successfully!", this->
get_name().c_str());
43 case ESP_GATTC_CLOSE_EVT: {
44 ESP_LOGW(TAG,
"[%s] Disconnected!", this->
get_name().c_str());
49 case ESP_GATTC_SEARCH_CMPL_EVT: {
55 ESP_LOGW(TAG,
"No sensor characteristic found at service %s char %s", this->
service_uuid_.
to_string().c_str(),
56 this->char_uuid_.to_string().c_str());
61 auto *descr = chr->get_descriptor(this->
descr_uuid_);
62 if (descr ==
nullptr) {
65 ESP_LOGW(TAG,
"No sensor descriptor found at service %s char %s descr %s",
67 this->descr_uuid_.to_string().c_str());
70 this->
handle = descr->handle;
73 auto status = esp_ble_gattc_register_for_notify(this->
parent()->get_gattc_if(),
74 this->
parent()->get_remote_bda(), chr->handle);
76 ESP_LOGW(TAG,
"esp_ble_gattc_register_for_notify failed, status=%d",
status);
79 this->
node_state = espbt::ClientState::ESTABLISHED;
83 case ESP_GATTC_READ_CHAR_EVT: {
84 if (param->read.status != ESP_GATT_OK) {
85 ESP_LOGW(TAG,
"Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
88 if (param->read.handle == this->handle) {
94 case ESP_GATTC_NOTIFY_EVT: {
95 ESP_LOGD(TAG,
"[%s] ESP_GATTC_NOTIFY_EVT: handle=0x%x, value=0x%x", this->
get_name().c_str(),
96 param->notify.handle, param->notify.value[0]);
97 if (param->notify.handle != this->handle)
102 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
103 if (param->reg_for_notify.handle == this->handle) {
104 if (param->reg_for_notify.status != ESP_GATT_OK) {
105 ESP_LOGW(TAG,
"Error registering for notifications at handle %d, status=%d", param->reg_for_notify.handle,
106 param->reg_for_notify.status);
109 this->
node_state = espbt::ClientState::ESTABLISHED;