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);
115 uint8_t battery_command = ACCESS_CONTROL_POINT_COMMAND;
116 uint8_t cccd_value[2] = {1, 0};
119 if (chr ==
nullptr) {
120 ESP_LOGW(TAG,
"No access control point characteristic found at service %s char %s",
122 this->access_control_point_characteristic_uuid_.to_string().c_str());
127 CLIENT_CHARACTERISTIC_CONFIGURATION_DESCRIPTOR_UUID);
128 if (descr ==
nullptr) {
130 this->access_control_point_characteristic_uuid_.to_string().c_str());
135 esp_ble_gattc_register_for_notify(this->
parent()->get_gattc_if(), this->
parent()->get_remote_bda(), chr->handle);
137 ESP_LOGW(TAG,
"esp_ble_gattc_register_for_notify failed, status=%d", reg_status);
146 2, cccd_value, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
148 ESP_LOGW(TAG,
"Error sending CCC descriptor write request, status=%d", descr_status);
154 &battery_command, ESP_GATT_WRITE_TYPE_RSP, ESP_GATT_AUTH_REQ_NONE);
156 ESP_LOGW(TAG,
"Error sending read request for battery, status=%d", chr_status);