I 'm trying to run esp32 as a multi-client.
I have been experimenting with using the gattc_multi_connect.c example.
I do not use a ble scan, but when I received a command through uart, I connect to it using the BDA address.
BDA ADDR1 : 00 00 00 00 00 01
BDA ADDR2 : 00 00 00 00 00 02
Code: Select all
#define PROFILE_NUM 2
#define PROFILE_A_APP_ID 0
#define PROFILE_B_APP_ID 1
static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = {
[PROFILE_A_APP_ID] = {
.gattc_cb = gattc_profile_a_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 */
},
ret = esp_ble_gattc_app_register(PROFILE_A_APP_ID);
if (ret){
ESP_LOGE(GATTC_TAG, "gattc app register error, error code = %x", ret);
return;
}
ret = esp_ble_gattc_app_register(PROFILE_B_APP_ID);
if (ret){
ESP_LOGE(GATTC_TAG, "gattc app register error, error code = %x", ret);
return;
}
Code: Select all
for (i = 0; i < PROFILE_NUM; i++) {
if(gl_profile_tab[i].is_connected == false) {
esp_ble_gattc_open(gl_profile_tab[i].gattc_if, [b]addr[/b], BLE_ADDR_TYPE_PUBLIC, true);
return ESP_OK;
}
}
2. uart command ( CONNECT (ADDR2)) received --> esp_ble_gattc_open (ADDR2); --> gattc_profile_b_event_handler
For the device corresponding to ADDR1, the event is handled through the gattc_profile_a_event_handler,
ADDR2 is processed in gattc_profile_b_event_handler.
There is no problem in operation when connecting for the first time. (write/read char, notification)
3. After disconnecting, (ADDR1, ADDR2)
Code: Select all
esp_ble_gap_disconnect(ADDR1);
esp_ble_gap_disconnect(ADDR2);
uart command ( CONNECT (ADDR2)) received --> esp_ble_gattc_open (ADDR2); --> gattc_profile_a_event_handler
The corresponding device of ADDR2 is processed through gattc_profile_a_event_handler, not gattc_profile_b_event_handler.
When an ADDR2 device transfers data over a notification, the esp32 client performs unexpected behavior.
- E (1838663) esp_gattc_cb: EVT 10, gattc if 3, app_id 22639
W (1838673) event_'A': ESP_GATTC_NOTIFY_EVT, Receive notify value:
I (1838673) event_'A': 02 06 01 11 00 21 75 3c da 3c e5 3d 0b 3c be 3c
I (1838683) event_'A': f0 3c fb 3d 03 3c df 3c e8 3c d7 3c e0 3c cb 3c
I (1838693) event_'A': e7 3c e7 3c e3 3c 45 2a 03
E (1838713) esp_gattc_cb: EVT 10, gattc if 4, app_id 22639
W (1838713) event_'B': ESP_GATTC_NOTIFY_EVT, Receive notify value:
I (1838713) event_'B': 02 06 01 11 00 21 75 3c da 3c e5 3d 0b 3c be 3c
I (1838723) event_'B': f0 3c fb 3d 03 3c df 3c e8 3c d7 3c e0 3c cb 3c
I (1838733) event_'B': e7 3c e7 3c e3 3c 45 2a 03
but, gattc_profile_b_event_handler also generates an ESP_GATTC_NOTIFY_EVT event.
Can anyone help me?
Thanks in advance.