网上的例程都是连接多个server的各一个service。自己尝试修改官方的例程:
- /* One gatt-based profile one app_id and one gattc_if, this array will store the gattc_if returned by ESP_GATTS_REG_EVT */
- static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = {
- [PROFILE_A_APP_ID] = {
- .gattc_cb = gattc_profile_event_handler,
- .gattc_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
- },
- [PROFILE_B_APP_ID] = {
- .gattc_cb = gattc_profile_b_event_handler,
- .gattc_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
- },
- };
- esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);
- esp_ble_gattc_open(gl_profile_tab[PROFILE_B_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true);