2021-07-21 04:20 PM
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.
Solved! Go to Solution.
2021-07-22 04:37 PM
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;
2021-07-22 02:45 AM
aci_gap_set_non_discoverable();
it is working for me !
2021-07-22 04:37 PM
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;