BLE Not starting advertising after disconnect

jjwsei
Posts: 6
Joined: Fri Mar 01, 2019 1:31 pm

BLE Not starting advertising after disconnect

Postby jjwsei » Tue Apr 21, 2020 1:43 pm

I am currently using release/v3.3 of the esp-idf and am running the ESP32 WROOM-32D as a GATT Server. When a client connects to the server I see all the expected events. Now when the client disconnects, I see the disconnect event but the server does not start advertising again. My code was essentially built upon the GATTS_DEMO from the idf.

I have added code to the GATTS_DISCONNECT_EVT that issues the gap_start_advertising() command, even though I don't feel it should be necessary. The command returns an ESP_OK however advertising does not seem to be restarting as the device is not visible in any BT scanning app I run.

I have seen issues like this reported in past versions of the idf, however, there was no real solution provided. I am using release/V3.3 as this is mentioned to be the latest stable version and I am targeting the ESP32 for a commercial product.

Any help would be greatly appreciated.

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: BLE Not starting advertising after disconnect

Postby abansal22 » Thu Apr 23, 2020 5:40 am

I think there is something wrong with the code. Check mine. It should be look like that.
  1. case ESP_GATTS_DISCONNECT_EVT:{
  2.       ESP_LOGI(bleTag,"ESP_GATTS_DISCONNECT_EVT event called");
  3.       esp_err_t ret = esp_ble_gap_set_device_name(btName);
  4.         ESP_LOGI(bleTag, "name set is done  %s\n", esp_err_to_name(ret));
  5.         if (ret){
  6.             ESP_LOGE(bleTag, "set device name failed, error code = %s", esp_err_to_name(ret));
  7.         }
  8.          ret = esp_ble_gap_config_adv_data(&adv_data);
  9.         if (ret){
  10.             ESP_LOGE(bleTag, "config adv data failed, error code = %x", ret);
  11.         }
  12.         adv_config_done |= adv_config_flag;
  13.  
  14.         ret = esp_ble_gap_config_adv_data(&scan_rsp_data);
  15.         ESP_LOGI(bleTag, "response of scan data = %s", esp_err_to_name(ret));
  16.         adv_config_done |= scan_rsp_config_flag;
  17.         heart_rate.conn_id = 0xffff;
  18.        
  19.     }break;

If you still facing the error, Please paste the whole code here. thanks!

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

Re: BLE Not starting advertising after disconnect

Postby chegewara » Fri Apr 24, 2020 5:20 pm

jjwsei wrote:
Tue Apr 21, 2020 1:43 pm
I have added code to the GATTS_DISCONNECT_EVT that issues the gap_start_advertising() command, even though I don't feel it should be necessary. The command returns an ESP_OK however advertising does not seem to be restarting as the device is not visible in any BT scanning app I run.
It is up to you, designer, to decide when you want to start advertising. It can be right after disconnecting, or after connecting so you could have connected multiple central or one hour after disconnect, on push button, timer, or never.
There is so many possibilities so it would be not wise to force users to stop advertising, only because your use case is to advertise after disconnect.

color99
Posts: 2
Joined: Sun Oct 24, 2021 1:13 am

Re: BLE Not starting advertising after disconnect

Postby color99 » Sun Oct 24, 2021 1:29 am

I use latest Arduino IDE and latest ESP32 add-on to debug a very simple BLE project. I have the same problem: ESP32 stop advertising after a client disconnect to it. The C++ code posted can not be added into my Arduino code for ESP32. Is there any way to solve this problem?

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: BLE Not starting advertising after disconnect

Postby abansal22 » Sun Oct 24, 2021 9:47 am

color99 wrote:
Sun Oct 24, 2021 1:29 am
I use latest Arduino IDE and latest ESP32 add-on to debug a very simple BLE project. I have the same problem: ESP32 stop advertising after a client disconnect to it. The C++ code posted can not be added into my Arduino code for ESP32. Is there any way to solve this problem?
Please send out the code I can look into it. Above code is for the esp -idf only. Thanks!

Who is online

Users browsing this forum: Google [Bot], sparks and 124 guests