BLE Scan Resp Raw Data: Examples in esp_idf not sending scan response data in raw mode

ziolelle
Posts: 6
Joined: Tue Apr 17, 2018 1:40 pm

BLE Scan Resp Raw Data: Examples in esp_idf not sending scan response data in raw mode

Postby ziolelle » Wed Dec 12, 2018 8:41 am

Hi, it seems really strange to me that only me is getting this kind of problem:

I took examples from the "examples/bluetooth" folder in esp_idf and no one is working correctly when activating CONFIG_SET_RAW_ADV_DATA

I made few tests and I report here the simplest:
working on "examples/bluetooth/ble_compatibility_test"

I simply changed (activating( the define for CONFIG_SET_RAW_ADV_DATA in ble_compatibility_test.c

Code: Select all

 
#define CONFIG_SET_RAW_ADV_DATA 1
I changed a little the arrays raw_adv_data[], raw_scan_rsp_data[] just to let mw show something more than the default, and I inserted manufacturer data
The same, but modifying the correct strutcts, I made in "esp_ble_adv_data_t adv_data" and "esp_ble_adv_data_t scan_rsp_data"

First test, I compiled and loaded the example in ESP32 using the code WITHOUT activating CONFIG_SET_RAW_ADV_DATA
nRF Connect on my iPhone showed me manufacturer data and twice the Service UUID are advertized.
(why do we have to define the 128bit Service UUID two times???? once in adv_data and once in scan_rsp_data).

Code: Select all

//#define CONFIG_SET_RAW_ADV_DATA 1
static uint8_t service_uuid[16] = {
    /* LSB <--------------------------------------------------------------------------------> MSB */
    //first uuid, 16bit, [12],[13] is the value
    0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00,
};

static uint8_t test_manufacturer[] = {0x55, 0xaa, 0x55, 0xaa };

/* The length of adv data must be less than 31 bytes */
static esp_ble_adv_data_t adv_data = {
    .set_scan_rsp        = false,
    .include_name        = true,
    .include_txpower     = true,
    .min_interval        = 0x20,
    .max_interval        = 0x40,
    .appearance          = 0x00,
    .manufacturer_len    = 0,    //TEST_MANUFACTURER_DATA_LEN,
    .p_manufacturer_data = NULL, //test_manufacturer,
    .service_data_len    = 0,
    .p_service_data      = NULL,
    .service_uuid_len    = sizeof(service_uuid),
    .p_service_uuid      = service_uuid,
    .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
};

// scan response data
static esp_ble_adv_data_t scan_rsp_data = {
    .set_scan_rsp        = true,
    .include_name        = true,
    .include_txpower     = true,
    .min_interval        = 0x20,
    .max_interval        = 0x40,
    .appearance          = 0x00,
//    .manufacturer_len    = 0, //TEST_MANUFACTURER_DATA_LEN,
//    .p_manufacturer_data = NULL, //&test_manufacturer[0],
    .manufacturer_len    = sizeof(test_manufacturer),
    .p_manufacturer_data = test_manufacturer,
    .service_data_len    = 0,
    .p_service_data      = NULL,
    .service_uuid_len    = 16,
    .p_service_uuid      = service_uuid,
    .flag = (ESP_BLE_ADV_FLAG_GEN_DISC | ESP_BLE_ADV_FLAG_BREDR_NOT_SPT),
};
Link to nRF Screenshot:
https://www.dropbox.com/s/iljcv26iecg0r ... 1.PNG?dl=0


After that I tried to activate CONFIG_SET_RAW_ADV_DATA inserting the manufacturer data in raw_adv_data.
nRF Connect showed me the manufacturer data correctly but only one time the Service UUID (ignoring the one in raw_scan_rsp_data ??)

Code: Select all

#define CONFIG_SET_RAW_ADV_DATA 1

#ifdef CONFIG_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {
        /* flags */
        0x02, 0x01, 0x06,
        /* tx power*/
        0x02, 0x0a, 0xeb,
        /* service uuid */
        0x03, 0x03, 0xFF, 0x00,
        /* device name */
        0x0E, 0x09, 'B', 'L', 'E', '_', 'C', 'O','M', 'P', '_', 'R','A', 'W', '1'
	/* DMT Manufacturer Data */
	,0x05, 0xff, 0x55, 0xaa, 0x55, 0xaa
};
static uint8_t raw_scan_rsp_data[] = {
        /* flags */
        0x02, 0x01, 0x06,
        /* tx power */
        0x02, 0x0a, 0xeb,
        /* service uuid */
        0x03, 0x03, 0xFF,0x00
	/* DMT Manufacturer Data */
	//,0x05, 0xff, 0x55, 0xaa, 0x55, 0xaa
};
Link to nRF Screenshot:
https://www.dropbox.com/s/kqesx9oym9lqs ... 3.PNG?dl=0


Last test has been activation of CONFIG_SET_RAW_ADV_DATA and setting manufacturer data in raw_scan_rsp_data.
nRF Connect didn't showed me any manufacturer data and only one time the Service UUID (ignoring all the data in raw_scan_rsp_data).

Code: Select all

#define CONFIG_SET_RAW_ADV_DATA 1

#ifdef CONFIG_SET_RAW_ADV_DATA
static uint8_t raw_adv_data[] = {
        /* flags */
        0x02, 0x01, 0x06,
        /* tx power*/
        0x02, 0x0a, 0xeb,
        /* service uuid */
        0x03, 0x03, 0xFF, 0x00,
        /* device name */
        0x0E, 0x09, 'B', 'L', 'E', '_', 'C', 'O','M', 'P', '_', 'R','A', 'W', '0'
	/* DMT Manufacturer Data */
	//,0x05, 0xff, 0x55, 0xaa, 0x55, 0xaa
};
static uint8_t raw_scan_rsp_data[] = {
        /* flags */
        0x02, 0x01, 0x06,
        /* tx power */
        0x02, 0x0a, 0xeb,
        /* service uuid */
        0x03, 0x03, 0xFF,0x00
	/* DMT Manufacturer Data */
	,0x05, 0xff, 0x55, 0xaa, 0x55, 0xaa
};
Link to nRF Screenshot:
https://www.dropbox.com/s/jbqn8xim5o8hp ... 2.PNG?dl=0


I tried also to modify the parameters in

Code: Select all

static esp_ble_adv_params_t adv_params = {
    .adv_int_min         = 0x40,
    .adv_int_max         = 0x40,
    .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,
};
setting the value adv_type to ADV_TYPE_SCAN_IND:

Code: Select all

static esp_ble_adv_params_t adv_params = {
    .adv_int_min         = 0x40,
    .adv_int_max         = 0x40,
    .adv_type            = ADV_TYPE_SCAN_IND,
    .own_addr_type       = BLE_ADDR_TYPE_PUBLIC,
    .channel_map         = ADV_CHNL_ALL,
    .adv_filter_policy   = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
};
but without success...

A part these little changed I didn't make any change to the code provided by Espressif.

Am I making something wrong ??

Ciao
Daniele

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE Scan Resp Raw Data: Examples in esp_idf not sending scan response data in raw mode

Postby chegewara » Wed Dec 12, 2018 11:01 pm

Hi,
answering on your first question:
no, you dont have to advertise 128bit UUID two times. It is just example to show how you can do it, but in real app you can have advertising data completely different than scan response data.

Answering the other question, example seems to look ok when you read code. Try to check if flags are set properly in this part of code:
https://github.com/espressif/esp-idf/bl ... #L286-L297
and advertising starts in line 295 not in line 289.

ziolelle
Posts: 6
Joined: Tue Apr 17, 2018 1:40 pm

Re: BLE Scan Resp Raw Data: Examples in esp_idf not sending scan response data in raw mode

Postby ziolelle » Thu Dec 13, 2018 1:32 pm

chegewara wrote:
Wed Dec 12, 2018 11:01 pm
Hi,
answering on your first question:
no, you dont have to advertise 128bit UUID two times. It is just example to show how you can do it, but in real app you can have advertising data completely different than scan response data.

Answering the other question, example seems to look ok when you read code. Try to check if flags are set properly in this part of code:
https://github.com/espressif/esp-idf/bl ... #L286-L297
and advertising starts in line 295 not in line 289.
Hi !

For the first question: ok, I can understand this is an example.

For the second answer: the flags are ok, also because, without the correct set/unset of the flags, the advertising souldn't start, and this is confirmed by the fact that the event ESP_GAP_BLE_ADV_START_COMPLETE_EVT is generated correctly in both cases (with or without using raw data).

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE Scan Resp Raw Data: Examples in esp_idf not sending scan response data in raw mode

Postby chegewara » Thu Dec 13, 2018 8:01 pm

That not exactly correct. Advertising will start if in this line returns true (flag==0):
https://github.com/espressif/esp-idf/bl ... est.c#L288

This shouldnt happen in this example code, but its worth to check. Just add log output somewhere in here:
https://github.com/espressif/esp-idf/bl ... est.c#L289

or just ignore me.

ziolelle
Posts: 6
Joined: Tue Apr 17, 2018 1:40 pm

Re: BLE Scan Resp Raw Data: Examples in esp_idf not sending scan response data in raw mode

Postby ziolelle » Fri Dec 14, 2018 7:55 am

chegewara wrote:
Thu Dec 13, 2018 8:01 pm
That not exactly correct. Advertising will start if in this line returns true (flag==0):
https://github.com/espressif/esp-idf/bl ... est.c#L288

This shouldnt happen in this example code, but its worth to check. Just add log output somewhere in here:
https://github.com/espressif/esp-idf/bl ... est.c#L289

or just ignore me.
Don't agree.. the flags are put there in order to signal to the handler when to start the advertising. And the advertising must start only when both the other events are received. And this is working correctly.
The same mechanism is in place for event not related to raw data and it works perfectly.

I repeat: if one or both messages are not sent, the advertising wouldn't start, and this is not the case: the advertising starts, and only after both the messages are sent.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: BLE Scan Resp Raw Data: Examples in esp_idf not sending scan response data in raw mode

Postby chegewara » Fri Dec 14, 2018 8:40 am

Its you right to disagree. I know you can advertise only regular advertising packet, scan response packet or both. Thats why there is 2 esp_ble_gap_start_advertising(&adv_params); lines. If this line
https://github.com/espressif/esp-idf/bl ... est.c#L289

will run before this finish:
https://github.com/espressif/esp-idf/bl ... #L473-L477

then only regular advertising will be seen during scan. But like i said, its you right to have opinion and not take my answers for real.

Who is online

Users browsing this forum: No registered users and 26 guests