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

BLE manual connect and Disconnect

Dear Nordic Team, 

Thanks for supporting.

I am working in ble_app_uart_c example in this example is automatically connect with its peripheral. But i need to connect and disconnect manually like  nRF_UART android app. please support anyone.

My HW = DK52

SDK = SDK15.2.0

  • Hi,

    The ble_app_uart_c example uses the scan module and configures it so that it will automatically connect if it finds a peripheral with the NUS service. If you want to control weather to connect or disconnect yourself I would say that the most natural would be to modify the example so that it only calls scan_start() (which in turn calls nrf_ble_scan_start()) when you want to connect, or instance after a button press. You may also want to stop scanning after a timeout or for another reason. In that case you can call nrf_ble_scan_stop(). Similarly you could use a button press to decide if you should call sd_ble_gap_disconnect() to disconnect (allready implemented in the example, just search for BSP_EVENT_DISCONNECT).

  • Thanks for reply. connection and disconnection ok , but I want to collect the peripheral list and choose one from the list for connection. Here when we start scan its automatically connected. 

    Flow : 1) Start Scan 2) List the peripheral 3) Choose one from list for connection 4) Then Disconnect when we need

           

  • I see. Then, referring to NUS central example, you should do the initial scanning with connect_if_match set to false to find all peripherals that match your criteria. Then when you subsequently want to connect to a specific peripheral you adjust the criteria so that it only matches one of them (typically filtering on the BLE address using SCAN_ADDR_FILTER). Then set connect_if_match to true before you start to scan so that it will connect to the peripheral with the specific address.

  • in SDK12.3.0 i have complete my requirement. Function on_ble_evt have BLE_GAP_EVT_ADV_REPORT field, here i will do filter name(p=strstr((const char *)p_adv_report->data,"Nordic_UART")) , list the peripherals and connect if match UUID  (is_uuid_present(&m_nus_uuid, p_adv_report)). but i dont have option in SDK15.2.0 .

  • also i am tried as per your suggestion set init_scan.connect_if_match = false and add some code in ble_evt_handler like below 

    case BLE_GAP_EVT_ADV_REPORT:

    ble_gap_evt_adv_report_t const * p_adv_report;
    uint16_t data_len;
    data_len = p_adv_report->data.len;

    if (ble_advdata_name_find(p_adv_report->data.p_data,data_len,"Nordic_UART"))
    {

    NRF_LOG_INFO("Scan Device %02x%02x%02x%02x%02x%02x",
    p_adv_report->peer_addr.addr[0],
    p_adv_report->peer_addr.addr[1],
    p_adv_report->peer_addr.addr[2],
    p_adv_report->peer_addr.addr[3],
    p_adv_report->peer_addr.addr[4],
    p_adv_report->peer_addr.addr[5]
    );
    }

    break;

    but unable to process ble_advdata_name_find () this function. 

Related