This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can not stop advertising in BLE event handler

I tried code like

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
....
    case BLE_GAP_EVT_TIMEOUT:
        if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT)
        {	
				err_code = sd_ble_gap_adv_stop();		// Stop advertising if not connected in limited time
				APP_ERROR_CHECK(err_code);	
        }
        break;
....
}

However, it returned error NRF_ERROR_INVALID_STATE.

Is there any other way to stop advertising just after timeout? Thanks.

Parents
  • When you configure advertising timeout with adv_params.timeout when you start advertising with sd_ble_gap_adv_start(&adv_params) it means that after this interval of time if no one connect to your device then it'll stop advertising automatically.

    When you meet condition (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) it meens that advertising has timed out and stopped. So you get NRF_ERROR_INVALID_STATE because advertising already stopped when you call sd_ble_gap_adv_stop().

Reply
  • When you configure advertising timeout with adv_params.timeout when you start advertising with sd_ble_gap_adv_start(&adv_params) it means that after this interval of time if no one connect to your device then it'll stop advertising automatically.

    When you meet condition (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) it meens that advertising has timed out and stopped. So you get NRF_ERROR_INVALID_STATE because advertising already stopped when you call sd_ble_gap_adv_stop().

Children
No Data
Related