This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ble_advertising_evt_handler_t doesn't get called

After flashing softdevice, the ble_advertising_evt_handler_t doesn't get called, only after flashing the program for the 4th time.

/**@brief Function for initializing advertising module.
 */
static void ble_advertise_init(void) {
	ble_advdata_t advdata;
	ble_adv_modes_config_t options;

	// Build advertising data struct to pass into @ref ble_advertising_init.
	memset(&advdata, 0, sizeof(advdata));

	advdata.name_type = BLE_ADVDATA_FULL_NAME;
	advdata.include_appearance = true;
	advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;

	memset(&options, 0, sizeof(options));
	options.ble_adv_fast_enabled = true;
	options.ble_adv_fast_interval = APP_ADV_INTERVAL;
	options.ble_adv_fast_timeout = 0;

	APP_ERROR_CHECK(ble_advertising_init(&advdata, NULL, &options, ble_on_advertising_evt, NULL));
}

/**@brief Function for starting the advertising.
 */
static void ble_advertise_start(void) {
	ret_code_t err_code;
	err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
	if(err_code != NRF_SUCCESS){
		APP_ERROR_CHECK(err_code);
	}
}

Does anyone had this problem, or have any idea how to solve it?

  • Hi ricsilvs,

    Which firmware you were testing with ?

    Which event you were expecting to receive ? Have you received BLE_GAP_EVT_TIMEOUT event ? Usually you get the ble_on_advertising_evt() called when there is a timeout in an advertising mode.

  • I've defined the .ble_adv_fast_timeout = 0, on the ble_on_advertising_evt(), I'm printing the advertising event:

    /**@brief Function for handling a Advertising event.
     */
    static void ble_on_advertising_evt(ble_adv_evt_t const adv_evt){
    	NRF_LOG_INFO("ble_on_advertising_evt(): State = %d\n", adv_evt);
    }
    

    What is really bothering me is the fact that everytime I flash softdevice it only starts advertising at the 4th (!!!) time I flash the program.

  • Please try to test with our example. It doesn't make much sense that you have to flash 4 times to make it work.

    If you set the timeout = 0, it will keep advertising forever, how which event do you expect to receive ?

  • I've already tested with nordic examples and I didn't had this problem. This example is for test only, so no problem with advertising forever. The event I expect to receive is "BLE_ADV_MODE_FAST"

  • The event handler is called at line 551 in ble_advertising_start() .

    if (m_evt_handler != NULL)
    {
        m_evt_handler(m_adv_evt);
    }
    

    If you step into the code you should see it's called after you call advertising_start()

1 2 3 4