Sequence flow for BLE advertising ... must I wait for an ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Sequence flow for BLE advertising ... must I wait for an ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT?

Postby kolban » Thu Jun 22, 2017 4:39 am

When creating a BLE peripheral which will be advertising its existence, I understand that I must call:

esp_ble_gap_config_adv_data()

to set the content of the advertisement and then call

esp_ble_gap_start_advertising()

to begin the actual advertising procedure.

However, my question is about timing. When we call:

esp_ble_gap_config_adv_data()

at some time later we will receive an ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT that indicates that the advertising data has been set. My core question is as follows:

Do I have to wait for the ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT event before calling esp_ble_gap_start_advertising() or can I call esp_ble_gap_start_advertising() immediately following a call to esp_ble_gap_config_adv_data()?

I could see either being valid and am hoping to hear the sequence rules in effect.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

ESP_Island
Posts: 36
Joined: Thu Jun 29, 2017 7:20 am

Re: Sequence flow for BLE advertising ... must I wait for an ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT?

Postby ESP_Island » Thu Jun 29, 2017 9:07 am

It is allowed to call “set adv data”, “set scan rsp data” and “start adv” together under the condition that adv data and scan rsp data are all correctly set. Calling “Start adv” before adv data being set correctly will cause that peripheral advertises NULL packets, which may cause unexpected result.

So it is better to wait for “adv data set completed event” and “scan response set completed event” (if you have scan response) before start advertising.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 120 guests