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

Disable BLE failed

Hi,

I am using nrf52832 with softdevice s132. The peripheral device is nrf52832 and central device is a mobile app. I want to disable BLE in nrf52832 and I am using this:

    uint32_t disable_ble(void)
    {
        if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
        }
        err_code = sd_ble_gap_adv_stop(m_advertising.adv_handle);
        return err_code;
    }

I see that when I call this function without connection between my app and device, I worked. But when there is a connection, after device nrf52832 disconnect from app and disable adv, my app try to reconnect immediately, and the app can reconnect. I think that sd_ble_gap_adv_stop() take softdevice a couple of time and if central app request connect in this time, sd_ble_gap_adv_stop() will fail. Have anyone face this issue and is there any workaround for it?
Thanks alot!
Parents
  • Hi, 

    my app try to reconnect immediately, and the app can reconnect.

    Did you enable auto-connect function on the mobile app as this post?  If so, you could disable the function. 

    -Amanda H.

  • Thanks for your respond, it's a good solution for this. I found another workaround: There are 2 case happen when we disable BLE, when connecting and when non-connecting. In case of connecting. I disconnect and in on_adv_evt(), case BLE_ADV_EVT_FAST (I am using fast adv), I call sd_ble_gap_adv_stop(). In case of non-connecting, it means ble is advertising, I just have to call sd_ble_gap_adv_stop() in disable_ble().

    bool run_adv = true;
    
    uint32_t disable_ble(void)
    {
        uint32_t err_code;
        if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
            run_adv = false;
        }
        else
        {
            err_code = sd_ble_gap_adv_stop(m_advertising.adv_handle);
        }
        return err_code;
    }
    
    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    {
        uint32_t err_code;
        switch (ble_adv_evt)
        {
            case BLE_ADV_EVT_FAST:
                if (run_adv == false)
                {
                    sd_ble_gap_adv_stop(m_advertising.adv_handle);
                }
                break;
            case BLE_ADV_EVT_IDLE:
                sleep_mode_enter();
                break;
            default:
                break;
        }
    }

Reply
  • Thanks for your respond, it's a good solution for this. I found another workaround: There are 2 case happen when we disable BLE, when connecting and when non-connecting. In case of connecting. I disconnect and in on_adv_evt(), case BLE_ADV_EVT_FAST (I am using fast adv), I call sd_ble_gap_adv_stop(). In case of non-connecting, it means ble is advertising, I just have to call sd_ble_gap_adv_stop() in disable_ble().

    bool run_adv = true;
    
    uint32_t disable_ble(void)
    {
        uint32_t err_code;
        if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
        {
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            if (err_code != NRF_SUCCESS)
            {
                return err_code;
            }
            run_adv = false;
        }
        else
        {
            err_code = sd_ble_gap_adv_stop(m_advertising.adv_handle);
        }
        return err_code;
    }
    
    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
    {
        uint32_t err_code;
        switch (ble_adv_evt)
        {
            case BLE_ADV_EVT_FAST:
                if (run_adv == false)
                {
                    sd_ble_gap_adv_stop(m_advertising.adv_handle);
                }
                break;
            case BLE_ADV_EVT_IDLE:
                sleep_mode_enter();
                break;
            default:
                break;
        }
    }

Children
No Data
Related