14 esp_ble_gattc_cb_param_t *param) {
16 case ESP_GATTC_OPEN_EVT: {
17 if (param->open.status == ESP_GATT_OK) {
18 ESP_LOGI(TAG,
"Connected successfully!");
23 case ESP_GATTC_DISCONNECT_EVT: {
27 ESP_LOGW(TAG,
"Disconnected!");
31 case ESP_GATTC_SEARCH_CMPL_EVT: {
34 this->
node_state = espbt::ClientState::ESTABLISHED;
47 case ESP_GATTC_READ_CHAR_EVT: {
48 if (param->read.conn_id != this->parent()->get_conn_id())
50 if (param->read.status != ESP_GATT_OK) {
51 ESP_LOGW(TAG,
"Error reading char at handle %d, status=%d", param->read.handle, param->read.status);
54 if (param->read.handle == this->handle_) {
55 this->
read_sensors(param->read.value, param->read.value_len);
60 case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
61 this->
node_state = espbt::ClientState::ESTABLISHED;
65 case ESP_GATTC_NOTIFY_EVT: {
66 if (param->notify.conn_id != this->parent()->get_conn_id())
68 if (param->notify.handle == this->acp_handle_) {
69 this->
read_battery_(param->notify.value, param->notify.value_len);
96 char service_buf[esp32_ble::UUID_STR_LEN];
97 char char_buf[esp32_ble::UUID_STR_LEN];
98 ESP_LOGW(TAG,
"No sensor characteristic found at service %s char %s", this->
service_uuid_.
to_str(service_buf),
99 this->sensors_data_characteristic_uuid_.to_str(char_buf));
106 ESP_GATT_AUTH_REQ_NONE);
108 ESP_LOGW(TAG,
"Error sending read request for sensor, status=%d",
status);
117 uint8_t battery_command = ACCESS_CONTROL_POINT_COMMAND;
118 uint8_t cccd_value[2] = {1, 0};
121 if (chr ==
nullptr) {
122 char service_buf[esp32_ble::UUID_STR_LEN];
123 char char_buf[esp32_ble::UUID_STR_LEN];
124 ESP_LOGW(TAG,
"No access control point characteristic found at service %s char %s",
125 this->
service_uuid_.
to_str(service_buf), this->access_control_point_characteristic_uuid_.to_str(char_buf));
130 CLIENT_CHARACTERISTIC_CONFIGURATION_DESCRIPTOR_UUID);
131 if (descr ==
nullptr) {
132 char service_buf[esp32_ble::UUID_STR_LEN];
133 char char_buf[esp32_ble::UUID_STR_LEN];
134 ESP_LOGW(TAG,
"No CCC descriptor found at service %s char %s", this->
service_uuid_.
to_str(service_buf),
135 this->access_control_point_characteristic_uuid_.to_str(char_buf));
140 esp_ble_gattc_register_for_notify(this->
parent()->get_gattc_if(), this->
parent()->get_remote_bda(), chr->handle);
142 ESP_LOGW(TAG,
"esp_ble_gattc_register_for_notify failed, status=%d", reg_status);
151 2, cccd_value, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
153 ESP_LOGW(TAG,
"Error sending CCC descriptor write request, status=%d", descr_status);
159 &battery_command, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
161 ESP_LOGW(TAG,
"Error sending read request for battery, status=%d", chr_status);