cancel
Showing results for 
Search instead for 
Did you mean: 

How to start broadcasting BLE using the p2p server example after disconnection.

Warning
Associate II

Hey,

I am trying to make a device which connect to an app using stm32wb15. Everything works properly, but I want to make it so that when the device becomes disconnected, i can use a button to broadcast BLE so that i can connect through an app again. I tried the existing ready functions. But I could not seem to make it visible as a Bluetooth device again (have to restart the device) 

Can someone point me to which functions i should call in the main.c to start broadcasting durign button press. 

1 ACCEPTED SOLUTION

Accepted Solutions
FilipKremen
ST Employee

Hello,

for advertising you can use Adv_Request(APP_BLE_FAST_ADV) function.

CFG_TASK_ADV_CANCEL_ID is ID for the task that cancels the advertising.

You need this ID for registering and running the task in the sequencer (scheduler for tasks).

Utility:Sequencer - stm32mcu

Please read this document below as it might be helpful for you.

How to build wireless applications with STM32WB MCUs - Application note

I recommend reading section 4.4/4.5 and 7.

If you have any question, please don't hesitate to ask.

You could also share the project if it is possible, so I could help you further with your application.

Best regards,

Filip Kremen

View solution in original post

4 REPLIES 4
FilipKremen
ST Employee

Hello,

I would suggest creating a task for start advertising (in the same way as CFG_TASK_ADV_CANCEL_ID) and then you can call Adv_Start_Req (Adv_Cancel_Req for cancel advertising) from one of the APP_BLE_Key_ButtonX_Action function. Please let me know if it works on your side.

Best regards,

Filip Kremen

 

Warning
Associate II

Hi, I am new to this. So i do not understand what i should do. CFG_TASK_ADV_CANCEL_ID ?

Here is what i have:

static void Button_Check(void)

{

uint8_t button_current_state = HAL_GPIO_ReadPin(button_GPIO_Port, button_Pin);

uint32_t current_time = HAL_GetTick();

 

if (button_last_state == 0 && button_current_state == 1) {

if (current_time - last_button_time > 100) {

last_button_time = current_time;

 

// 1. Confirmation vibration

Vibration_Pulse(100);

 

// 2. Direct BLE stack call (no external dependencies)

aci_gap_set_non_discoverable();

HAL_Delay(500);

 

// Start advertising with direct call

tBleStatus ret = aci_gap_set_discoverable(

ADV_IND, // Advertising type

0x0020, // Min interval (20ms)

0x0040, // Max interval (40ms)

0x00, // Own address type

NO_WHITE_LIST_USE, // No whitelist

7, // Local name length

(uint8_t*)"BackTra", // Device name

0, // Service UUID length

NULL, // Service UUIDs

0x0006, // Min conn interval

0x0C80 // Max conn interval

);

 

// 3. Feedback based on result

if (ret == BLE_STATUS_SUCCESS) {

// Success: 3 quick vibrations

Vibration_Pulse(100);

HAL_Delay(100);

Vibration_Pulse(100);

HAL_Delay(100);

Vibration_Pulse(100);

} else {

// Failed: 1 long vibration

Vibration_Pulse(500);

}

}

}

 

button_last_state = button_current_state;

}

I saw this as well, and i tried using it, but it did not work. Can you tell me which function from the app_ble i should call to start advertising?

/**

* Start to Advertise to be connected by P2P Client

*/

Adv_Request(APP_BLE_FAST_ADV);

 

/* USER CODE BEGIN APP_BLE_Init_2 */

 

/* USER CODE END APP_BLE_Init_2 */

 

FilipKremen
ST Employee

Hello,

for advertising you can use Adv_Request(APP_BLE_FAST_ADV) function.

CFG_TASK_ADV_CANCEL_ID is ID for the task that cancels the advertising.

You need this ID for registering and running the task in the sequencer (scheduler for tasks).

Utility:Sequencer - stm32mcu

Please read this document below as it might be helpful for you.

How to build wireless applications with STM32WB MCUs - Application note

I recommend reading section 4.4/4.5 and 7.

If you have any question, please don't hesitate to ask.

You could also share the project if it is possible, so I could help you further with your application.

Best regards,

Filip Kremen

Hey. I read about sequencing and Now it works! Thank you.