Article Directory
The general process of BLE connection establishment
1. Before starting to connect with Client
1. ESP_GATTS_REG_EVT 注册
2. ESP_GATTS_CREATE_EVT 创建
3. ESP_GATTS_START_EVT 启动
4. ESP_GATTS_ADD_CHAR_EVT 添加特征
5. ESP_GATTS_ADD_CHAR_DESCR_EVT 添加特征描述
1) Registration: ESP_GATTS_REG_EVT
Call esp_ble_gap_set_device_name(char *)
to set the name of the Bluetooth device;
Call esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
to configure broadcast data;
Finally, call the esp_ble_gatts_create_service(esp_gatt_if_t gatts_if, esp_gatt_srvc_id_t *service_id, uint16_t num_handle)
specified gatts_if
sum service_id
to create the service (the bottom layer btc_transfer_context()
implements the creation of the service and the call of the callback function by calling).
When the service is created, the callback function is triggered to profile
report the status and service ID. Service_id
For subsequent additions included serivces
and characteristics/descriptor
all need to be used.
The ESP_GATTS_CREATE_EVT
event is triggered at the same time .
2) ESP_GATTS_CREATE_EVT
Call esp_ble_gatts_start_service(uint16_t service_handle)
to start the service;
Call again esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_uuid, esp_gatt_perm_t perm, esp_gatt_char_prop_t property, esp_attr_value_t *char_val, esp_attr_control_t *control)
to add features (feature UUID, feature value descriptor attribute permission, feature attribute, feature value, attribute response control byte).
Triggers ESP_GATTS_START_EVT
and ESP_GATTS_ADD_CHAR_EVT
events.
3) ESP_GATTS_START_EVT
(slightly)
4) ESP_GATTS_ADD_CHAR_EVT
Get feature value call esp_err_tesp_ble_gatts_add_char_descr(uint16_t service_handle, esp_bt_uuid_t *descr_uuid, esp_gatt_perm_tperm, esp_attr_value_t *char_descr_val, esp_attr_control_t *control)
to add feature descriptor.
5) ESP_GATTS_ADD_CHAR_DESCR_EVT
(slightly)
2. After starting to connect with Client
1. CONNECT_EVT 连接
2. ESP_GATTS_MTU_EVT
3. GATT_WRITE_EVT (client)写(server)事件
4. ESP_GATTS_CONF_EVT 配置事件
5. GATT_READ_EVT (client)读(server)事件
Reference
https://blog.csdn.net/zhejfl/article/details/85136102#comments_14573948