esp_ble_gap_set_device_name does not update the name

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

esp_ble_gap_set_device_name does not update the name

Postby zazas321 » Mon Jan 31, 2022 5:51 am

I am working on the developing the program on the ESP32 device. My task requires to create a custom BLE advertising name.
I have noticed a strange issue with esp_ble_gap_set_device_name function. I have 2 questions:

1. When I pass char array to the function esp_ble_gap_set_device_name and restart the device. I can still see my device advertise the old name. I have tried to unpair the device but it is still the same. Could someone help me understand how it works and what I need to do so the BLE advertising name updates?

Code: Select all

    switch (event) {
        case ESP_GATTS_REG_EVT:
            
            char test_ble_name[20];
            strcpy(test_ble_name,"TEST_BLE");
            esp_ble_gap_set_device_name(test_ble_name);
            }
            ...
            ...
            ...
            

Now in my Lightblue App I should see my device advertise with the name "TEST_BLE" but instead it is set to something that I had before.
Last edited by zazas321 on Tue Feb 01, 2022 5:49 am, edited 1 time in total.

manikantateja
Posts: 8
Joined: Thu Jan 27, 2022 6:13 am

Re: esp_ble_gap_set_device_name does not update the name

Postby manikantateja » Mon Jan 31, 2022 10:12 am

Try to change name in BLE advertisement data, you will see name change in light blue application after connection.

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: esp_ble_gap_set_device_name does not update the name

Postby zazas321 » Tue Feb 01, 2022 5:21 am

Please can you clarify what you mean?

My structures are set to:

Code: Select all


static esp_ble_adv_data_t elstat_adv_config = {
    .set_scan_rsp = false,
    .include_txpower = true,
    .min_interval = 0x0006, //slave connection min interval, Time = min_interval * 1.25 msec
    .max_interval = 0x0010, //slave connection max interval, Time = max_interval * 1.25 msec
    .appearance = 0x00,
    .manufacturer_len = 0, 
    .p_manufacturer_data =  NULL, 
    .service_data_len = 0,
    .p_service_data = NULL,
    .service_uuid_len = sizeof(sec_service_uuid),
    .p_service_uuid = sec_service_uuid,
    .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
};

static esp_ble_adv_params_t elstat_adv_params = {
    .adv_int_min        = 0x100,
    .adv_int_max        = 0x100,
    .adv_type           = ADV_TYPE_IND,
    .own_addr_type      = BLE_ADDR_TYPE_PUBLIC,
    .channel_map        = ADV_CHNL_ALL,
    .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};


The only place in the code where I set the GAP device name is the ESP_GATTS_REG_EVT:

Code: Select all

static void gatts_profile_event_handler(esp_gatts_cb_event_t event,
                                        esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
{
    ESP_LOGV(GATTS_TABLE_TAG, "event = %x\n",event);
    switch (event) {
        case ESP_GATTS_REG_EVT:
            
            char test_ble_name[20] = "HELLO123";
            esp_ble_gap_set_device_name(test_ble_name);
            esp_ble_gap_config_local_privacy(true);
            esp_ble_gatts_create_attr_tab(heart_rate_gatt_db, gatts_if,
                                      ELSTAT_IDX_NB, ELSTAT_SVC_INST_ID);
                                      
            
And changing above does not change the BLE device name immediately. Sometimes I need to restart device multiple times, unpair and pair multiple times til finally all of a sudden the name changes. There must be a way to have it change reliably

manikantateja
Posts: 8
Joined: Thu Jan 27, 2022 6:13 am

Re: esp_ble_gap_set_device_name does not update the name

Postby manikantateja » Tue Feb 01, 2022 5:53 am

static uint8_t ext_adv_raw_data[] = {
0x02, 0x01, 0x06,
0x02, 0x0a, 0xeb, 0x03, 0x03, 0xab, 0xcd,
0x11, 0X09, 'E', 'S', 'P', '_', 'B', 'L', 'E', '5', '0', '_', 'S', 'E', 'R', 'V', 'E', 'R',
};
you can find the advertisement raw data like above, in that array based on your required name change the length field "0x11" and keep advertisement type id "0x09" as constant and change the name according to your required name.

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: esp_ble_gap_set_device_name does not update the name

Postby zazas321 » Tue Feb 01, 2022 7:41 am

I am slowly starting to understand where are you going but not quite. At the moment, I do not use raw advertisement data in my program.

I read this to understand more about BLE packet and format:
https://community.silabs.com/s/article/ ... uage=en_US

In the lightblue APP, I can see the following raw advertisement packet: (Also see the image of LightBlue screenshot):

0x02 01 06
0x02 0A 03
0x03 03 18 0D
0x05 12 06 00 11 00

1. Could you help me understand what do the above raw advertisement packet means?


2. In order to achieve what you have said, I need to advertise raw packet. Do I still need esp_ble_gap_set_device_name or its no longer needed? How does raw advertisement data set the device name?
Attachments
Screenshot_20220201-084150_LightBlue.jpg
Screenshot_20220201-084150_LightBlue.jpg (338.4 KiB) Viewed 9434 times

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: esp_ble_gap_set_device_name does not update the name

Postby zazas321 » Tue Feb 01, 2022 9:30 am

I have been further learning about BLE raw advertising packets. I am aware of how the BLE data is decoded
1st byte = length
2nd byte = Types
n-1 = actual data

but I still do not understand why this data needs to sent as advertisement data. Is it important for the client device to receive this data up?

In the example that you have posted above:

Code: Select all

static uint8_t ext_adv_raw_data[] = {
0x02, 0x01, 0x06,
0x02, 0x0a, 0xeb, 
0x03, 0x03, 0xab, 0xcd,
0x11, 0X09, 'E', 'S', 'P', '_', 'B', 'L', 'E', '5', '0', '_', 'S', 'E', 'R', 'V', 'E', 'R',
};

Can you explain what is 0x02, 0x01, 0x06 and why do we need to put it in the raw data packet?
Can you explain what is 0x02, 0x0a, 0xeb and why do we need to put it in the raw data packet?
Can you explain what is 0x03, 0x03, 0xab, 0xcd and why do we need to put it in the raw data packet?


0x02, 0x01, 0x06,
0x02, 0x0a, 0xeb,
0x03, 0x03, 0xab, 0xcd,
Occupies 10 bytes. Since maximum advertisement data length is 31 bytes, that leaves me 21 bytes for my device name which is not enough for us. Can we just remove 0x02, 0x0a, 0xeb, and save 3 bytes? Is that going to cause us some issues?

manikantateja
Posts: 8
Joined: Thu Jan 27, 2022 6:13 am

Re: esp_ble_gap_set_device_name does not update the name

Postby manikantateja » Tue Feb 01, 2022 9:41 am

https://www.bluetooth.com/specification ... d-numbers/

follow above link and see generic access profile for advertisement types.
Advertisement data helps the client to know about the device link name, services, flags...

manikantateja
Posts: 8
Joined: Thu Jan 27, 2022 6:13 am

Re: esp_ble_gap_set_device_name does not update the name

Postby manikantateja » Tue Feb 01, 2022 9:49 am

by using advertisement data we can update name, its enough for connection.
2)
0x02, 0x01, 0x06,
tells about flags in 0x06 -
Bit 0 :Indicates LE Limited Discoverable mode
Bit 1:Indicates LE General Discoverable mode
Bit 2:Indicates whether BR/EDR is not supported .
Bit 3:Indicates whether LE and BR/EDR operate simultaneously (controller)
Bit 4: Simultaneous LE and BR/EDR to same device capable(Host
Bit 5...7 : Reserved
means peripheral is telling it supports LE General Discoverable mode and BR/EDR is not supported .

0x02, 0x0a, 0xeb,
tells about Tx Power Level

0x03, 0x03, 0xab, 0xcd,
it tells about services provided by peripheral

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Re: esp_ble_gap_set_device_name does not update the name

Postby zazas321 » Tue Feb 01, 2022 10:54 am

Okay I see. It is a little bit more clear now. So there is really no big deal if I just remove the 3 bytes from the TX power 0x02, 0x0a, 0xeb,
and leave 3 more bytes for my complete local name as 21 bytes are not enough but we can get away with 24 bytes

Who is online

Users browsing this forum: Baidu [Spider], Muntazer and 118 guests