Good afternoon,
I just managed to implement an advertiser using the Bluedroid stack.
Now I would like to implement a Gatt DB (Add Services, Characteristics) and manage
all of the BLE Events :
- When a characteristic has been writtent.
- When a service has been discovered
- When a connection has been openened
- When a connection has been closed.
What is the best example to use in order to work on these features please ?
Best regards,
Thomas TRUILHE
ESP32-S3-DevKitC-1 : What is the best example to implement a Gatt DB ?
-
- Posts: 229
- Joined: Thu Jul 14, 2022 5:15 am
-
- Posts: 229
- Joined: Thu Jul 14, 2022 5:15 am
Re: ESP32-S3-DevKitC-1 : What is the best example to implement a Gatt DB ?
I have used the example project gatt_server_service_table in order to create a Gatt DB in my device.
In order to debug the program, I have placed some printf during the initialisation of the Bluetooth and everything
seems to be oK.
- The controller is initialised and enabled normally.
- The Bluedroid stack is initialised and enabled normally.
- The Gatts callback is registered correctly.
- The GAP callback is registered correctly.
- When the application is registered using the function : ret = esp_ble_gatts_app_register(ESP_APP_ID), the ESP_GATTS_REG_EVT event is raised in the Gatt callback and is transfered to the Profile callback.
- In this ESP_GATTS_REG_EVT event, I execute the methods esp_ble_gap_config_adv_data_raw, esp_ble_gap_config_scan_rsp_data_raw and esp_ble_gatts_create_attr_tab.
Everything seems to be OK, I mean my device advertise normally, I can find it using an BLE application for example EFR Connect,
I can connect to it and I see the log message :
TaskBluetooth : gatts_profile_event_handler : ESP_GATTS_CONNECT_EVT, conn_id = 0.
Update connection params status = 0, min_int = 0, max_int = 0,conn_int = 6,latency = 0, timeout = 2000Update connection params status = 0, min_int = 0, max_int = 0,conn_int = 36,latency = 0, timeout = 2000W (24243) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13
However, using the EFR connect software, I do not see my services and characteristics.
So I can't try to Read or to write them.
I am not sure to understand how to define the services and characteristics in this example. I think it is the problem.
And this is what I have to solve.
I have kept the GattDB of the example :
static const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
{
// Service Declaration
[IDX_SVC] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_TEST), (uint8_t *)&GATTS_SERVICE_UUID_TEST}},
/* Characteristic Declaration */
[IDX_CHAR_A] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write_notify}},
/* Characteristic Value */
[IDX_CHAR_VAL_A] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_A, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_CFG_A] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(uint16_t), sizeof(heart_measurement_ccc), (uint8_t *)heart_measurement_ccc}},
/* Characteristic Declaration */
[IDX_CHAR_B] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read}},
/* Characteristic Value */
[IDX_CHAR_VAL_B] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
/* Characteristic Declaration */
[IDX_CHAR_C] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_write}},
/* Characteristic Value */
[IDX_CHAR_VAL_C] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
};
In the last chip I used (Silicon Labs), the IDE integrated a graphical tool that can be used to defined the GattDB.
I would like to keep the GattDB created using the graphical tool and to insert it into the Espressif program but I don't know how to do that.
You will find the xml file of the GattDB that I would like to insert in my program.
Could you please help me ?
Best regards,
Thomas TRUILHE
In order to debug the program, I have placed some printf during the initialisation of the Bluetooth and everything
seems to be oK.
- The controller is initialised and enabled normally.
- The Bluedroid stack is initialised and enabled normally.
- The Gatts callback is registered correctly.
- The GAP callback is registered correctly.
- When the application is registered using the function : ret = esp_ble_gatts_app_register(ESP_APP_ID), the ESP_GATTS_REG_EVT event is raised in the Gatt callback and is transfered to the Profile callback.
- In this ESP_GATTS_REG_EVT event, I execute the methods esp_ble_gap_config_adv_data_raw, esp_ble_gap_config_scan_rsp_data_raw and esp_ble_gatts_create_attr_tab.
Everything seems to be OK, I mean my device advertise normally, I can find it using an BLE application for example EFR Connect,
I can connect to it and I see the log message :
TaskBluetooth : gatts_profile_event_handler : ESP_GATTS_CONNECT_EVT, conn_id = 0.
Update connection params status = 0, min_int = 0, max_int = 0,conn_int = 6,latency = 0, timeout = 2000Update connection params status = 0, min_int = 0, max_int = 0,conn_int = 36,latency = 0, timeout = 2000W (24243) BT_HCI: hcif disc complete: hdl 0x1, rsn 0x13
However, using the EFR connect software, I do not see my services and characteristics.
So I can't try to Read or to write them.
I am not sure to understand how to define the services and characteristics in this example. I think it is the problem.
And this is what I have to solve.
I have kept the GattDB of the example :
static const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
{
// Service Declaration
[IDX_SVC] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
sizeof(uint16_t), sizeof(GATTS_SERVICE_UUID_TEST), (uint8_t *)&GATTS_SERVICE_UUID_TEST}},
/* Characteristic Declaration */
[IDX_CHAR_A] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read_write_notify}},
/* Characteristic Value */
[IDX_CHAR_VAL_A] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_A, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
/* Client Characteristic Configuration Descriptor */
[IDX_CHAR_CFG_A] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
sizeof(uint16_t), sizeof(heart_measurement_ccc), (uint8_t *)heart_measurement_ccc}},
/* Characteristic Declaration */
[IDX_CHAR_B] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_read}},
/* Characteristic Value */
[IDX_CHAR_VAL_B] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_B, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
/* Characteristic Declaration */
[IDX_CHAR_C] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ,
CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_write}},
/* Characteristic Value */
[IDX_CHAR_VAL_C] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&GATTS_CHAR_UUID_TEST_C, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
GATTS_DEMO_CHAR_VAL_LEN_MAX, sizeof(char_value), (uint8_t *)char_value}},
};
In the last chip I used (Silicon Labs), the IDE integrated a graphical tool that can be used to defined the GattDB.
I would like to keep the GattDB created using the graphical tool and to insert it into the Espressif program but I don't know how to do that.
You will find the xml file of the GattDB that I would like to insert in my program.
Could you please help me ?
Best regards,
Thomas TRUILHE
- Attachments
-
- gatt.xml
- (9.43 KiB) Downloaded 171 times
Who is online
Users browsing this forum: No registered users and 117 guests