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

SDK 14 BLE connection state function missing

Hello,

we have a problem with a BLE connection state function. We are working with an NRF52832 device and SDK 14. The device itself works in central and peripharel mode. Since we have another device with SDK 15.2 with a working DFU Mode and buttonless bootloader we tried to convert the functions to SDK 14. But at the Event "Bootloader Enter Prepare" the function for "ble_conn_state_for_each_connected" is missing . What would be the best alternativ function in SDK 14 ? We tried "ble_conn_state_n_connections" but that wont really work.

        case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
        {
            NRF_LOG_INFO("Device is preparing to enter bootloader mode.");

            // Prevent device from advertising on disconnect.
            ble_adv_modes_config_t config;
            advertising_config_get(&config);
            config.ble_adv_on_disconnect_disabled = true;
            ble_advertising_modes_config_set(&m_advertising, &config);

            // Disconnect all other bonded devices that currently are connected.
            // This is required to receive a service changed indication
            // on bootup after a successful (or aborted) Device Firmware Update.
            uint32_t conn_count = ble_conn_state_for_each_connected(disconnect, NULL);
            //uint32_t conn_count = ble_conn_state_n_connections();
            //disconnect(conn_count,NULL);
            //ble_conn_state_n_connections
            NRF_LOG_INFO("Disconnected %d links.", conn_count);
            break;
        }
 

Best regards

Oliver

Parents
  • Hi Oliver, 

    I would recommend migrating the SDK v14.x.x device to to SDk v15.2.0 rather than downgrading the SDK v15.2.0 device to SDK v14.x.x. 

    The key point is to disconnect all peripheral connections, so you can use ble_conn_state_periph_handles() to get a list of the connection handles for connections and then lop through to that and call sd_ble_gap_disconnect with all the handles. 

    You can do the same with ble_conn_state_central_handles as well. 

    Best regards

    Bjørn

  • Hi Bjørn,

    I'm working in the same project as Oliver. First of all thanks for the suggestions. Updating to SDK v15.2.0 ist currently not an option due to lack of time.. So we want to establish the bootloader for the SDK v14.x.x device.

    The function ble_conn_state_periph_handles() returns a struct of type sdk_mapped_flags_key_list_t which containts a length and a flag list. How can we access the handles based on the returned values?

    Here is the temporary function:

    static ret_code_t disconnect_all_devices(void)
    {
        ret_code_t err_code;
        sdk_mapped_flags_key_list_t conn_handles = ble_conn_state_periph_handles();

        for (uint8_t i= 0; i < conn_handles.len; i++)
        {
            err_code = sd_ble_gap_disconnect( ? ,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

            if (err_code != NRF_SUCCESS)
            {
                APP_ERROR_CHECK(err_code);
                NRF_LOG_DEBUG("Error in disconnecting");
            }
        }
        return NRF_SUCCESS;
    }

    Thanks in advance!

  • I found a different solution: I check the handles directly, e.g.:

        if(BLE_CONN_HANDLE_INVALID!=m_conn_handle_peripheral)
        {
            err_code = sd_ble_gap_disconnect(m_conn_handle_peripheral,BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            NRF_LOG_INFO("disconnect KM, err_code= %d",err_code);
        }

Reply Children
Related