20 LOG_SENSOR(
"",
"BLE Sensor",
this);
21 char service_buf[esp32_ble::UUID_STR_LEN];
22 char char_buf[esp32_ble::UUID_STR_LEN];
23 char descr_buf[esp32_ble::UUID_STR_LEN];
26 " Service UUID : %s\n"
27 " Characteristic UUID: %s\n"
28 " Descriptor UUID : %s\n"
29 " Notifications : %s",
31 this->char_uuid_.to_str(char_buf), this->descr_uuid_.to_str(descr_buf), YESNO(this->
notify_));
32 LOG_UPDATE_INTERVAL(
this);
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: {
46 ESP_LOGW(TAG,
"[%s] Disconnected!", this->
get_name().c_str());
51 case ESP_GATTC_SEARCH_CMPL_EVT: {
57 char service_buf[esp32_ble::UUID_STR_LEN];
58 char char_buf[esp32_ble::UUID_STR_LEN];
59 ESP_LOGW(TAG,
"No sensor characteristic found at service %s char %s", this->
service_uuid_.
to_str(service_buf),
60 this->char_uuid_.to_str(char_buf));
65 auto *descr = chr->get_descriptor(this->
descr_uuid_);
66 if (descr ==
nullptr) {
69 char service_buf[esp32_ble::UUID_STR_LEN];
70 char char_buf[esp32_ble::UUID_STR_LEN];
71 char descr_buf[esp32_ble::UUID_STR_LEN];
72 ESP_LOGW(TAG,
"No sensor descriptor found at service %s char %s descr %s",
74 this->descr_uuid_.to_str(descr_buf));
77 this->
handle = descr->handle;
80 auto status = esp_ble_gattc_register_for_notify(this->
parent()->get_gattc_if(),
81 this->
parent()->get_remote_bda(), chr->handle);
83 ESP_LOGW(TAG,
"esp_ble_gattc_register_for_notify failed, status=%d",
status);
86 this->
node_state = espbt::ClientState::ESTABLISHED;
93 case ESP_GATTC_READ_CHAR_EVT: {
94 if (param->read.status != ESP_GATT_OK) {
95 ESP_LOGW(TAG,
"Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
98 if (param->read.handle == this->handle) {
104 case ESP_GATTC_NOTIFY_EVT: {
105 ESP_LOGD(TAG,
"[%s] ESP_GATTC_NOTIFY_EVT: handle=0x%x, value=0x%x", this->
get_name().c_str(),
106 param->notify.handle, param->notify.value[0]);
107 if (param->notify.handle != this->handle)
112 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
113 if (param->reg_for_notify.handle == this->handle) {
114 if (param->reg_for_notify.status != ESP_GATT_OK) {
115 ESP_LOGW(TAG,
"Error registering for notifications at handle %d, status=%d", param->reg_for_notify.handle,
116 param->reg_for_notify.status);
119 this->
node_state = espbt::ClientState::ESTABLISHED;
120 char char_buf[esp32_ble::UUID_STR_LEN];
121 ESP_LOGD(TAG,
"Register for notify on %s complete", this->
char_uuid_.
to_str(char_buf));