Hello,
I read what was reported on the forum https://esp32.com/viewtopic.php?f=13&t=2455
and I found an incompatibility between the management of the way to increase the value of MTU GATT Server between Espressif library and Nordic library.
I am using an Android APP (BLE client) where the MTU value is set by the Server which in my case was a Laird module with a Nordic chip.
In this case on the Nordic libraries for GATT Server the MTU update occurs when the Server communicates to the Client which MTU size to use.
In my case the Client doesn't have to do anything because it will always use the MTU size defined by the server.
With the ESP32-C3-MINI-1-H4 express module replacing the Laird (Nordic) module and with the same Android APP I saw that the
MTU value used is the default one (23) as the express module GATT Server does not send its MTU value that it wants to use after connection.
I have seen that on the Espressif libraries for GATT Server the MTU update occurs only upon request from the Client.
I didn't find any example on expressif for GATT Server on how to send the MTU value you want to use to the Client.
How can I solve this problem ?
Where can I find an example ?
I await your kind help.
Demetrio Magrin
Nordic library and Espressif (GATT - Server ) -> Are the ways of increasing the MTU size different
-
- Posts: 15
- Joined: Thu May 04, 2023 8:00 am
-
- Posts: 1696
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
-
- Posts: 15
- Joined: Thu May 04, 2023 8:00 am
Re: Nordic library and Espressif (GATT - Server ) -> Are the ways of increasing the MTU size different
Hello "MicroController",
thank you for your advice,
I imported the whole example into my GATT Server project and I have reported it below.
We have seen that some of the variables used in the example have not been declared in the example itself and are not even present in the basic project in "set the server's local MTU".
Requests:
1) Is it possible to have the main.c file of the example with also the variables used in the example (see "bb_measurementsCharValue[]") ?
2) Why are some variables of the "bb_measurementsCharValue[]" buffer incremented ?
What value do the remaining variables in the "bb_measurementsCharValue[]" buffer have ?
Is it just an example or is there a reason ?
3) In the example "gl_profile_tab[PROFILE_A_APP_ID].connected" the element ".connected" is not present in the structure
"gl_profile_tab[PROFILE_A_APP_ID]" nor in the basic project "set the server's local MTU".
Where is it ?
I await your kind reply.
Thanks
Magrin Demetrio
void app_main()
{
esp_err_t ret;
// Initialize NVS.
ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
ESP_LOGE(GATTS_TAG, "%s initialize controller failed\n", __func__);
return;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret) {
ESP_LOGE(GATTS_TAG, "%s enable controller failed\n", __func__);
return;
}
ret = esp_bluedroid_init();
if (ret) {
ESP_LOGE(GATTS_TAG, "%s init bluetooth failed\n", __func__);
return;
}
ret = esp_bluedroid_enable();
if (ret) {
ESP_LOGE(GATTS_TAG, "%s enable bluetooth failed\n", __func__);
return;
}
ret = esp_ble_gatts_register_callback(gatts_event_handler);
if (ret){
ESP_LOGE(GATTS_TAG, "gatts register error, error code = %x", ret);
return;
}
ret = esp_ble_gap_register_callback(gap_event_handler);
if (ret){
ESP_LOGE(GATTS_TAG, "gap register error, error code = %x", ret);
return;
}
ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
if (ret){
ESP_LOGE(GATTS_TAG, "gatts app register error, error code = %x", ret);
return;
}
ret = esp_ble_gatts_app_register(PROFILE_B_APP_ID);
if (ret){
ESP_LOGE(GATTS_TAG, "gatts app register error, error code = %x", ret);
return;
}
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(50);
if (local_mtu_ret){
ESP_LOGE(GATTS_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
}
// init gpio2 as output
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = (1ULL<<2);
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
//Init ADC and Characteristics
// esp_adc_cal_characteristics_t characteristics;
// adc1_config_width(ADC_WIDTH_BIT_12);
// adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_DB_11);
// esp_adc_cal_get_characteristics(V_REF, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, &characteristics);
uint8_t currentGpioState = 0;
gpio_set_level(2, currentGpioState);
while(1){
// if (currentGpioState)
// currentGpioState = 0;
// else
// currentGpioState = 1;
// gpio_set_level(2, currentGpioState);
// gatts_bb_measurementsCharValue.attr_value[0] = currentGpioState;
// vTaskDelay(pdMS_TO_TICKS(10000));
// pulseVoltage = adc1_to_voltage(ADC1_TEST_CHANNEL, &characteristics);
// printf("%d mV\n",pulseVoltage);
// if (threshold < pulseVoltage) {
// char_pulseVal[0] = 1ULL;
// //gatts_demo_pulseVoltage_val.attr_value[0] = 1ULL;
//
// }
// else {
// char_pulseVal[0] = NULL;
// //gatts_demo_pulseVoltage_val.attr_value[0] = NULL;
//
// }
if (gl_profile_tab[PROFILE_A_APP_ID].connected) {
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(155);
if (local_mtu_ret){
ESP_LOGE(GATTS_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
}
static int j = 0;
gpio_set_level(2, 1);
esp_ble_gatts_send_indicate(gl_profile_tab[PROFILE_A_APP_ID].gatts_if, gl_profile_tab[PROFILE_A_APP_ID].conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle,
gatts_bb_measurementsCharValue.attr_len, gatts_bb_measurementsCharValue.attr_value, false);
// currentGpioState = char_pulseVal[0];
// gpio_set_level(2, gatts_demo_pulseVoltage_val.attr_value[0]);
for (int i = 6; i <= 9; i++)
bb_measurementsCharValue++;
bb_measurementsCharValue[16]++;
j++;
if (j > 8) {
bb_measurementsCharValue[6] = 91;
bb_measurementsCharValue[7] = 85;
bb_measurementsCharValue[8] = 100;
bb_measurementsCharValue[9] = 90;
bb_measurementsCharValue[16] = 11;
j = 0;
}
}
vTaskDelay(pdMS_TO_TICKS(200));
gpio_set_level(2, 0);
vTaskDelay(pdMS_TO_TICKS(19800));
}
return;
}
thank you for your advice,
I imported the whole example into my GATT Server project and I have reported it below.
We have seen that some of the variables used in the example have not been declared in the example itself and are not even present in the basic project in "set the server's local MTU".
Requests:
1) Is it possible to have the main.c file of the example with also the variables used in the example (see "bb_measurementsCharValue[]") ?
2) Why are some variables of the "bb_measurementsCharValue[]" buffer incremented ?
What value do the remaining variables in the "bb_measurementsCharValue[]" buffer have ?
Is it just an example or is there a reason ?
3) In the example "gl_profile_tab[PROFILE_A_APP_ID].connected" the element ".connected" is not present in the structure
"gl_profile_tab[PROFILE_A_APP_ID]" nor in the basic project "set the server's local MTU".
Where is it ?
I await your kind reply.
Thanks
Magrin Demetrio
void app_main()
{
esp_err_t ret;
// Initialize NVS.
ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
ESP_LOGE(GATTS_TAG, "%s initialize controller failed\n", __func__);
return;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret) {
ESP_LOGE(GATTS_TAG, "%s enable controller failed\n", __func__);
return;
}
ret = esp_bluedroid_init();
if (ret) {
ESP_LOGE(GATTS_TAG, "%s init bluetooth failed\n", __func__);
return;
}
ret = esp_bluedroid_enable();
if (ret) {
ESP_LOGE(GATTS_TAG, "%s enable bluetooth failed\n", __func__);
return;
}
ret = esp_ble_gatts_register_callback(gatts_event_handler);
if (ret){
ESP_LOGE(GATTS_TAG, "gatts register error, error code = %x", ret);
return;
}
ret = esp_ble_gap_register_callback(gap_event_handler);
if (ret){
ESP_LOGE(GATTS_TAG, "gap register error, error code = %x", ret);
return;
}
ret = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
if (ret){
ESP_LOGE(GATTS_TAG, "gatts app register error, error code = %x", ret);
return;
}
ret = esp_ble_gatts_app_register(PROFILE_B_APP_ID);
if (ret){
ESP_LOGE(GATTS_TAG, "gatts app register error, error code = %x", ret);
return;
}
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(50);
if (local_mtu_ret){
ESP_LOGE(GATTS_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
}
// init gpio2 as output
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = (1ULL<<2);
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);
//Init ADC and Characteristics
// esp_adc_cal_characteristics_t characteristics;
// adc1_config_width(ADC_WIDTH_BIT_12);
// adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_DB_11);
// esp_adc_cal_get_characteristics(V_REF, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, &characteristics);
uint8_t currentGpioState = 0;
gpio_set_level(2, currentGpioState);
while(1){
// if (currentGpioState)
// currentGpioState = 0;
// else
// currentGpioState = 1;
// gpio_set_level(2, currentGpioState);
// gatts_bb_measurementsCharValue.attr_value[0] = currentGpioState;
// vTaskDelay(pdMS_TO_TICKS(10000));
// pulseVoltage = adc1_to_voltage(ADC1_TEST_CHANNEL, &characteristics);
// printf("%d mV\n",pulseVoltage);
// if (threshold < pulseVoltage) {
// char_pulseVal[0] = 1ULL;
// //gatts_demo_pulseVoltage_val.attr_value[0] = 1ULL;
//
// }
// else {
// char_pulseVal[0] = NULL;
// //gatts_demo_pulseVoltage_val.attr_value[0] = NULL;
//
// }
if (gl_profile_tab[PROFILE_A_APP_ID].connected) {
esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(155);
if (local_mtu_ret){
ESP_LOGE(GATTS_TAG, "set local MTU failed, error code = %x", local_mtu_ret);
}
static int j = 0;
gpio_set_level(2, 1);
esp_ble_gatts_send_indicate(gl_profile_tab[PROFILE_A_APP_ID].gatts_if, gl_profile_tab[PROFILE_A_APP_ID].conn_id, gl_profile_tab[PROFILE_A_APP_ID].char_handle,
gatts_bb_measurementsCharValue.attr_len, gatts_bb_measurementsCharValue.attr_value, false);
// currentGpioState = char_pulseVal[0];
// gpio_set_level(2, gatts_demo_pulseVoltage_val.attr_value[0]);
for (int i = 6; i <= 9; i++)
bb_measurementsCharValue++;
bb_measurementsCharValue[16]++;
j++;
if (j > 8) {
bb_measurementsCharValue[6] = 91;
bb_measurementsCharValue[7] = 85;
bb_measurementsCharValue[8] = 100;
bb_measurementsCharValue[9] = 90;
bb_measurementsCharValue[16] = 11;
j = 0;
}
}
vTaskDelay(pdMS_TO_TICKS(200));
gpio_set_level(2, 0);
vTaskDelay(pdMS_TO_TICKS(19800));
}
return;
}
-
- Posts: 1696
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Nordic library and Espressif (GATT - Server ) -> Are the ways of increasing the MTU size different
Don't expect the 5-years-old snippet of code from the forum post to work as-is. Refer to the current/full example I linked to.
Who is online
Users browsing this forum: MicroController and 256 guests