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

BLE disconnect & adv_stop

Hi,

I have some problems with functions sd_ble_gap_disconnect and sd_ble_gap_adv_stop.

I got critical error when i try to disconnect or stop_adv and my phone is connected with my board.

code :

void advertising_stop(void){
	uint32_t err_code;
	err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
	APP_ERROR_CHECK(err_code);
	err_code = sd_ble_gap_adv_stop();
	APP_ERROR_CHECK(err_code);
}

I tried to disconnect only with :

void advertising_stop(void){
	uint32_t err_code;
	err_code = sd_ble_gap_adv_stop();
	APP_ERROR_CHECK(err_code);
}

But when i'm connected to my phone, the software of the board bug (critical error).

When my phone is not connected to my board, all is right, my board stop advertising.

Regards

Parents
  • thx for your anwser.

    now that is my function :

    static void advertising_stop(void){
    	uint32_t err_code;
    	if(isConnectedBle){
    		err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    		APP_ERROR_CHECK(err_code);
    	}
    	err_code = sd_ble_gap_adv_stop();
    	APP_ERROR_CHECK(err_code);
    }
    

    isconnectedble is a bool wich turn true if connected event come and false if disconnected event come. I tried to use => m_conn_handle != BLE_CONN_HANDLE_INVALID to know if there are a connection in run but doesnt work.

    The sd_ble_gap_disconnect() works.

    The sd_ble_gap_adv_stop() give me an NRF_ERROR_INVALID_STATE which mean that there are no advertissement ready.

    But when i dont use sd_ble_gap_adv_stop(), sd_ble_adv_disconnect() disconnect my phone and after that, launch advertising.

    I dont really understand the problem.

    Regards,

    EDIT ANSWER :

    i didnt touch the library file and i just add a nrf_delay that allow times to softdevice to enable advertising and i stop it just after that.

    Regards,

    PS: my code here :

    static void advertising_stop(void){
    	uint32_t err_code;
    	if(isConnectedBle){
    		err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    		APP_ERROR_CHECK(err_code);
    	}
    	nrf_delay_ms(1000);
    	err_code = sd_ble_gap_adv_stop();
    	APP_ERROR_CHECK(err_code);
    }
    
  • What is it about the problem you don't understand? If you are in connection then you aren't advertising so stopping advertising will give you invalid state, which it does. If you break the connection then, if you're using some of the Nordic boilerplate code, that detects disconnect and re-starts advertising. If you don't want to advertise after disconnection, find that code, there's probably a configuration variable there somewhere, or write your own.

    This is all asynchronous, so just calling disconnect doesn't disconnect and re-start advertising right there, it starts the disconnect process, which eventually disconnects and calls back with an event, which is captured and advertising is re-started.

Reply
  • What is it about the problem you don't understand? If you are in connection then you aren't advertising so stopping advertising will give you invalid state, which it does. If you break the connection then, if you're using some of the Nordic boilerplate code, that detects disconnect and re-starts advertising. If you don't want to advertise after disconnection, find that code, there's probably a configuration variable there somewhere, or write your own.

    This is all asynchronous, so just calling disconnect doesn't disconnect and re-start advertising right there, it starts the disconnect process, which eventually disconnects and calls back with an event, which is captured and advertising is re-started.

Children
No Data
Related