17 esp_ble_gattc_cb_param_t *param) {
19 case ESP_GATTC_OPEN_EVT: {
20 if (param->open.status == ESP_GATT_OK) {
21 ESP_LOGI(TAG,
"Connected successfully!");
26 case ESP_GATTC_DISCONNECT_EVT: {
30 ESP_LOGW(TAG,
"Disconnected!");
34 case ESP_GATTC_SEARCH_CMPL_EVT: {
37 this->
node_state = espbt::ClientState::ESTABLISHED;
50 case ESP_GATTC_READ_CHAR_EVT: {
51 if (param->read.conn_id != this->parent()->get_conn_id())
53 if (param->read.status != ESP_GATT_OK) {
54 ESP_LOGW(TAG,
"Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
57 if (param->read.handle == this->handle_) {
58 this->
read_sensors(param->read.value, param->read.value_len);
63 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
64 this->
node_state = espbt::ClientState::ESTABLISHED;
68 case ESP_GATTC_NOTIFY_EVT: {
69 if (param->notify.conn_id != this->parent()->get_conn_id())
71 if (param->notify.handle == this->acp_handle_) {
72 this->
read_battery_(param->notify.value, param->notify.value_len);
99 char service_buf[esp32_ble::UUID_STR_LEN];
100 char char_buf[esp32_ble::UUID_STR_LEN];
101 ESP_LOGW(TAG,
"No sensor characteristic found at service %s char %s", this->
service_uuid_.
to_str(service_buf),
102 this->sensors_data_characteristic_uuid_.to_str(char_buf));
109 ESP_GATT_AUTH_REQ_NONE);
111 ESP_LOGW(TAG,
"Error sending read request for sensor, status=%d",
status);
120 uint8_t battery_command = ACCESS_CONTROL_POINT_COMMAND;
121 uint8_t cccd_value[2] = {1, 0};
124 if (chr ==
nullptr) {
125 char service_buf[esp32_ble::UUID_STR_LEN];
126 char char_buf[esp32_ble::UUID_STR_LEN];
127 ESP_LOGW(TAG,
"No access control point characteristic found at service %s char %s",
128 this->
service_uuid_.
to_str(service_buf), this->access_control_point_characteristic_uuid_.to_str(char_buf));
133 CLIENT_CHARACTERISTIC_CONFIGURATION_DESCRIPTOR_UUID);
134 if (descr ==
nullptr) {
135 char service_buf[esp32_ble::UUID_STR_LEN];
136 char char_buf[esp32_ble::UUID_STR_LEN];
137 ESP_LOGW(TAG,
"No CCC descriptor found at service %s char %s", this->
service_uuid_.
to_str(service_buf),
138 this->access_control_point_characteristic_uuid_.to_str(char_buf));
143 esp_ble_gattc_register_for_notify(this->
parent()->get_gattc_if(), this->
parent()->get_remote_bda(), chr->handle);
145 ESP_LOGW(TAG,
"esp_ble_gattc_register_for_notify failed, status=%d", reg_status);
154 2, cccd_value, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
156 ESP_LOGW(TAG,
"Error sending CCC descriptor write request, status=%d", descr_status);
162 &battery_command, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
164 ESP_LOGW(TAG,
"Error sending read request for battery, status=%d", chr_status);