15 esp_ble_gattc_cb_param_t *param) {
17 case ESP_GATTC_OPEN_EVT: {
18 if (param->open.status == ESP_GATT_OK) {
19 ESP_LOGI(TAG,
"Connected successfully!");
24 case ESP_GATTC_DISCONNECT_EVT: {
28 ESP_LOGW(TAG,
"Disconnected!");
32 case ESP_GATTC_SEARCH_CMPL_EVT: {
35 this->
node_state = espbt::ClientState::ESTABLISHED;
48 case ESP_GATTC_READ_CHAR_EVT: {
49 if (param->read.conn_id != this->parent()->get_conn_id())
51 if (param->read.status != ESP_GATT_OK) {
52 ESP_LOGW(TAG,
"Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
55 if (param->read.handle == this->handle_) {
56 this->
read_sensors(param->read.value, param->read.value_len);
61 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
62 this->
node_state = espbt::ClientState::ESTABLISHED;
66 case ESP_GATTC_NOTIFY_EVT: {
67 if (param->notify.conn_id != this->parent()->get_conn_id())
69 if (param->notify.handle == this->acp_handle_) {
70 this->
read_battery_(param->notify.value, param->notify.value_len);
97 char service_buf[esp32_ble::UUID_STR_LEN];
98 char char_buf[esp32_ble::UUID_STR_LEN];
99 ESP_LOGW(TAG,
"No sensor characteristic found at service %s char %s", this->
service_uuid_.
to_str(service_buf),
100 this->sensors_data_characteristic_uuid_.to_str(char_buf));
107 ESP_GATT_AUTH_REQ_NONE);
109 ESP_LOGW(TAG,
"Error sending read request for sensor, status=%d",
status);
118 uint8_t battery_command = ACCESS_CONTROL_POINT_COMMAND;
119 uint8_t cccd_value[2] = {1, 0};
122 if (chr ==
nullptr) {
123 char service_buf[esp32_ble::UUID_STR_LEN];
124 char char_buf[esp32_ble::UUID_STR_LEN];
125 ESP_LOGW(TAG,
"No access control point characteristic found at service %s char %s",
126 this->
service_uuid_.
to_str(service_buf), this->access_control_point_characteristic_uuid_.to_str(char_buf));
131 CLIENT_CHARACTERISTIC_CONFIGURATION_DESCRIPTOR_UUID);
132 if (descr ==
nullptr) {
133 char service_buf[esp32_ble::UUID_STR_LEN];
134 char char_buf[esp32_ble::UUID_STR_LEN];
135 ESP_LOGW(TAG,
"No CCC descriptor found at service %s char %s", this->
service_uuid_.
to_str(service_buf),
136 this->access_control_point_characteristic_uuid_.to_str(char_buf));
141 esp_ble_gattc_register_for_notify(this->
parent()->get_gattc_if(), this->
parent()->get_remote_bda(), chr->handle);
143 ESP_LOGW(TAG,
"esp_ble_gattc_register_for_notify failed, status=%d", reg_status);
152 2, cccd_value, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
154 ESP_LOGW(TAG,
"Error sending CCC descriptor write request, status=%d", descr_status);
160 &battery_command, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
162 ESP_LOGW(TAG,
"Error sending read request for battery, status=%d", chr_status);