Skip to main content
TomC
Senior
July 21, 2021
Solved

STM32WB - How to Stop Advertising Bluetooth Connection

  • July 21, 2021
  • 2 replies
  • 1127 views

To start advertising connection, I run

APPE_Init();

adv();

To stop advertising the connection, I run

aci_set_non_discoverable(connection_handle, reason);

aci_gap_terminate();

However the latter functions do not successfully cease advertising, I was wondering where I am going wrong.

This topic has been closed for replies.
Best answer by TomC

I was able to successfully use the Adv_Cancel() function in STM32_WPAN -> App -> app_ble.c by first checking the value of

BleApplicationContext.Device_Connection_Status

which is a static variable in app_ble.c. Adv_Cancel will not do anything if the value of Device_Connection_Status is APP_BLE_CONNECTED_SERVER(0x05). See Adv_Cancel()

static void Adv_Cancel( void )
{
/* USER CODE BEGIN Adv_Cancel_1 */
 
/* USER CODE END Adv_Cancel_1 */
 
 if (BleApplicationContext.Device_Connection_Status != APP_BLE_CONNECTED_SERVER)
 
 {
 
 tBleStatus result = 0x00;
 
 result = aci_gap_set_non_discoverable();
 
 BleApplicationContext.Device_Connection_Status = APP_BLE_IDLE;
 if (result == BLE_STATUS_SUCCESS)
 {
 APP_DBG_MSG(" \r\n\r");APP_DBG_MSG("** STOP ADVERTISING ** \r\n\r");
 }
 else
 {
 APP_DBG_MSG("** STOP ADVERTISING ** Failed \r\n\r");
 }
 
 }

Where I went wrong was not waiting for the value of BleApplicationContext.Device_Connection_Status to change from APP_BLE_CONNECTED_SERVER to something else after disconnection. See possible values for BleApplicationContext.Device_Connection_Status

typedef enum
 {
 APP_BLE_IDLE,
 APP_BLE_FAST_ADV,
 APP_BLE_LP_ADV,
 APP_BLE_SCAN,
 APP_BLE_LP_CONNECTING,
 APP_BLE_CONNECTED_SERVER,
 APP_BLE_CONNECTED_CLIENT
 } APP_BLE_ConnStatus_t;

2 replies

YSN
Associate III
July 22, 2021

aci_gap_set_non_discoverable();

it is working for me !

TomC
TomCAuthorBest answer
Senior
July 22, 2021

I was able to successfully use the Adv_Cancel() function in STM32_WPAN -> App -> app_ble.c by first checking the value of

BleApplicationContext.Device_Connection_Status

which is a static variable in app_ble.c. Adv_Cancel will not do anything if the value of Device_Connection_Status is APP_BLE_CONNECTED_SERVER(0x05). See Adv_Cancel()

static void Adv_Cancel( void )
{
/* USER CODE BEGIN Adv_Cancel_1 */
 
/* USER CODE END Adv_Cancel_1 */
 
 if (BleApplicationContext.Device_Connection_Status != APP_BLE_CONNECTED_SERVER)
 
 {
 
 tBleStatus result = 0x00;
 
 result = aci_gap_set_non_discoverable();
 
 BleApplicationContext.Device_Connection_Status = APP_BLE_IDLE;
 if (result == BLE_STATUS_SUCCESS)
 {
 APP_DBG_MSG(" \r\n\r");APP_DBG_MSG("** STOP ADVERTISING ** \r\n\r");
 }
 else
 {
 APP_DBG_MSG("** STOP ADVERTISING ** Failed \r\n\r");
 }
 
 }

Where I went wrong was not waiting for the value of BleApplicationContext.Device_Connection_Status to change from APP_BLE_CONNECTED_SERVER to something else after disconnection. See possible values for BleApplicationContext.Device_Connection_Status

typedef enum
 {
 APP_BLE_IDLE,
 APP_BLE_FAST_ADV,
 APP_BLE_LP_ADV,
 APP_BLE_SCAN,
 APP_BLE_LP_CONNECTING,
 APP_BLE_CONNECTED_SERVER,
 APP_BLE_CONNECTED_CLIENT
 } APP_BLE_ConnStatus_t;