How to communicate with specific peripheral during multiple peripherals BLE connection with NUS

Hello all. Now I am making a BLE network with multiple peripherals and central based on NUS. How could I make data transfer between the central and specific peripherals? I followed the "ble_app_multilink_central" in the example folder. I made two peripherals which name is "m_target_peripheral_name_1" and "m_target_peripheral_name_2". But the code doesn't work at all. So how can I make connection between specific peripheral and central? Thanks.

static void scan_init(void)
{
    ret_code_t          err_code;
    nrf_ble_scan_init_t init_scan;

    memset(&init_scan, 0, sizeof(init_scan));

    init_scan.connect_if_match = true;
    init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;

    err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
    APP_ERROR_CHECK(err_code);

    /* comment by Ming
    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
    APP_ERROR_CHECK(err_code);
    end by Ming */
    
    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_peripheral_name_1);              // set up peripheral name
    APP_ERROR_CHECK(err_code);

    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_peripheral_name_2);              // set up peripheral name
    APP_ERROR_CHECK(err_code);

    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
    APP_ERROR_CHECK(err_code);
    

}

Parents
  • Hi,

    What SDK and softdevice are you using?

    But the code doesn't work at all

    Could you provide me with more information? What doesn't work? Are you not able to connect? Are you not able to send data?

    What have you done so far? Have you made any modifications to the multilink example?

  • Hi Mttrinh, I modified the code based on nrf52-ble-app-uart-c-multilink-master from NordicPlayground on Github. I changed the scan_init() form SCAN_UUID_FILTER to SCAN_NAME_FILTER, which show below.

    /**@brief Function for initializing the scanning and setting the filters.
     */
    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.connect_if_match = true;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
        
        /*
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
        APP_ERROR_CHECK(err_code);
        */
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_peripheral_name_1);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);
        
    
    }

    After download the code, the debug information get from J-Linker RTT Viewer is shown below.

    Actually what I want to do is to send and receive data to specific peripheral in the BLE network of multiple peripherals and centrals. The service of BLE is NUS (Nordic UART Service). What I planned is to name different peripherals different name and access them individually.

    What's your suggestion? Thanks.

Reply
  • Hi Mttrinh, I modified the code based on nrf52-ble-app-uart-c-multilink-master from NordicPlayground on Github. I changed the scan_init() form SCAN_UUID_FILTER to SCAN_NAME_FILTER, which show below.

    /**@brief Function for initializing the scanning and setting the filters.
     */
    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.connect_if_match = true;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
        
        /*
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
        APP_ERROR_CHECK(err_code);
        */
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_peripheral_name_1);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);
        
    
    }

    After download the code, the debug information get from J-Linker RTT Viewer is shown below.

    Actually what I want to do is to send and receive data to specific peripheral in the BLE network of multiple peripherals and centrals. The service of BLE is NUS (Nordic UART Service). What I planned is to name different peripherals different name and access them individually.

    What's your suggestion? Thanks.

Children
No Data
Related