dhs2017 wrote:Below is the only code I added on top of the service table example code, it shows the error when I read the sensor location.
E (104789) BT: GATTS_SendRsp conn_id: 4 waiting for op_code = 00
E (104789) BT: Sending response failed
Code: Select all
case ESP_GATTS_READ_EVT:
memset(&rsp, 0, sizeof(esp_gatt_rsp_t));
rsp.attr_value.handle = heart_rate_handle_table[HRS_IDX_BOBY_SENSOR_LOC_VAL];
rsp.attr_value.len = sizeof(body_sensor_loc_val);
rsp.attr_value.value[0] = 0x01;
esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id,
ESP_GATT_OK, &rsp);
PROBLEM_1
Check the response type of the characteristic in your attribute table if it is response by app or auto reaponse:
Code: Select all
heart_rate_db[HRS_IDX_BODY_SENSOR_LOC_VAL].attr_control.auto_rsp = ESP_GATT_AUTO_RSP;
or
Code: Select all
heart_rate_db[HRS_IDX_BODY_SENSOR_LOC_VAL].attr_control.auto_rsp = ESP_GATT_RSP_BY_APP;
This will determine if you are the one handling the response or the bluetooth stack will do this for you.
PROBLEM_2
Also why are you hardcoding the handle? It is not necessary that this is the handle being read because for any gatt server read event it will read this handle irregardless if the user wants to read another characteristic or descriptor.
Try:
Code: Select all
rsp.attr_value.handle = param->read.handle;
Since during the discovery procedure the central device knows the handles of the data the gatt server exposes, if the central reads characteristic X and thus in the requests to read it by its handle Y that describes X but you send handle Z as response(That you have hardcoded), I believe an error may happen.
PROBLEM_3
Code: Select all
rsp.attr_value.len = sizeof(body_sensor_loc_val);
This length will always be 4 bytes as you are reading the size of the enumeration entry in the heart rate database. Even if the length of the data is longer. You should get the sizeof the data, not by the sizeof its entry number in the the database.
Correction:
Code: Select all
rsp.attr_value.len = sizeof(HEART_RATE_DB[body_sensor_loc_val]);
This code is valid if the entry is a single variable and not an array or struct for body_sensor_loc_val .