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.