cancel
Showing results for 
Search instead for 
Did you mean: 

How to start BLE advertising again after a disconnection from the central Android device

JMüll.1
Associate II

I am a student who is currently doing his bachelor thesis. My job is to control two microcontrollers (Nucleo-STM32F411RE) via Bluetooth (X-Nucleo-BNRG2A1) in order to transfer parameter values ​​for a system. The idea was to connect the microcontrollers one after the other via Bluetooth and transfer the values ​​of the parameters. The connection and the transfer of the values ​​works very well. Unfortunately, I am unable to connect a microcontroller a second time. When I terminate a connection, the device no longer appears in the scanner list or a reconnection hangs. I took the measures to be observed when closing a connection (gatt diconnect, gatt close in the callback, etc.). If I press the black reset button and restart the program, the device can be found in the scanner list immediately. Does anyone have experience with it? There are a lot of posts on this topic. So my question is: Can something be installed on the microcontroller side that will return to the advertising state in the event of a disconnect? Since 2 out of 3 months of my time have already passed, it would be helpful if someone had a snippet of code that I could include.

1 ACCEPTED SOLUTION

Accepted Solutions

I haven't used stm based ble products myself, so i cannot ​really help you more than pointing the direction you should look into, but since disconnection event is essential for any ble periephal/host device, it will be there somewhere.

Performing complete restart(init the whole ble again) will most likely wipe the characsterics values, but only enabling advertising again should retain the values, but as I can't be sure you propably want to keep those values in the memory of the microcontroller just to be sure you don't completely lose those.

About restarting the advertisement, im positive there is some command for that, since again it's essential for any ble device.

Once i get to home from work ​i can take a look at the proplem more closely.

View solution in original post

4 REPLIES 4
JoniS
Senior

Sure there is some kind of init sequence for the bluetooth part? Just follow the code at very beginning of execution chain.

Extract the part that does put the ble on advertising state and run that code when disconnection happens, or just run the init sequence again after ​disconnection.

JMüll.1
Associate II

Hi JoniS,

thank you for your immediate response. Do you know more about what event will happen when the connection was closed by the central device? Do you know more about which functions should be restarted then to get advertising started again? But, important is that the characteristics will not loose the values set because of the restart of the advertising!

Thank you very much.

I haven't used stm based ble products myself, so i cannot ​really help you more than pointing the direction you should look into, but since disconnection event is essential for any ble periephal/host device, it will be there somewhere.

Performing complete restart(init the whole ble again) will most likely wipe the characsterics values, but only enabling advertising again should retain the values, but as I can't be sure you propably want to keep those values in the memory of the microcontroller just to be sure you don't completely lose those.

About restarting the advertisement, im positive there is some command for that, since again it's essential for any ble device.

Once i get to home from work ​i can take a look at the proplem more closely.

JMüll.1
Associate II

Hi JoniS,

in the meantime and with your very good support I found the solution:

You have to add the hci_disconnection_complete_event callback function to your code and then you have to call hci_le_set_scan_response_data() and aci_gap_set_discoverable() once again. Now it works. Thank you very very much.

Kind regards.