ESP32-C3 BLE client 连接同一个server的多个service

lxttian
Posts: 2
Joined: Thu Nov 03, 2022 5:30 am

ESP32-C3 BLE client 连接同一个server的多个service

Postby lxttian » Thu Nov 03, 2022 5:58 am

最近在做一个项目需要ESP32-C3作为BLE client 连接同一个server的两个service。
网上的例程都是连接多个server的各一个service。自己尝试修改官方的例程:
  1. /* One gatt-based profile one app_id and one gattc_if, this array will store the gattc_if returned by ESP_GATTS_REG_EVT */
  2. static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = {
  3.     [PROFILE_A_APP_ID] = {
  4.         .gattc_cb = gattc_profile_event_handler,
  5.         .gattc_if = ESP_GATT_IF_NONE,       /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
  6.     },
  7.     [PROFILE_B_APP_ID] = {
  8.         .gattc_cb = gattc_profile_b_event_handler,
  9.         .gattc_if = ESP_GATT_IF_NONE,       /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */
  10.     },
  11. };
  1.  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);
  2. 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);
运行的时候会有heap相关的错误,无法成功。请问这样写是否合理? 有没有连接同一个设备不同service的例程?

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: ESP32-C3 BLE client 连接同一个server的多个service

Postby ESP_XuLZ » Thu Nov 03, 2022 10:03 am

两个设备只能建立一个物理连接的, 连接多个service 的意思就是 client 能够发现多个 service ?
在 gatt_client 示例中, ESP_GATTC_CONNECT_EVT 事件上来时, client 已经发现完成了对端的所有 service 的发现

你可以仔细看下gatt client 中这些 esp_ble_gattc_search_service()、esp_ble_gattc_get_attr_count() 和 esp_ble_gattc_get_char_by_uuid() 函数的说明和使用, 有些过滤选项需要换成你要连接的对端 server 的

Who is online

Users browsing this forum: No registered users and 94 guests