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

how to Stop advertise when ble are connected

hello.

I want to toggle ble functions when received message from UART.

so when start message come, I start advertising and start services and stop message come, disconnect(if it connected) and stop advertising.

       if(stop)
{
    if(m_conn_handle != BLE_CONN_HANDLE_INVALID) // ble connected
    {
      sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    }
    advertising_stop();
}

but when ble is connected, the advertising_stop() function is not working. because ble going to advertising state when device is connected.

How I Can handle this situation?

I want to disable BLE directly.

Parents
  • By default, when you get connected the softdevice automatically disable advertising unless you start it again. You don't have to stop advertising manually.

    In your code, if it's connected you should not call advertising_stop() because it's not advertising. You should do something like this:

          if(stop)
    {
        if(m_conn_handle != BLE_CONN_HANDLE_INVALID) // ble connected
        {
          sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        }
       else
       {
           advertising_stop();
       }
    }
    
Reply
  • By default, when you get connected the softdevice automatically disable advertising unless you start it again. You don't have to stop advertising manually.

    In your code, if it's connected you should not call advertising_stop() because it's not advertising. You should do something like this:

          if(stop)
    {
        if(m_conn_handle != BLE_CONN_HANDLE_INVALID) // ble connected
        {
          sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        }
       else
       {
           advertising_stop();
       }
    }
    
Children
No Data
Related