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

How to connect two nrf DK boards through BLE

hi, i have a requirement to connect two nrf51(PCA10028) boards to connect each other.

1).if i turn on the Board1 should scan the bluetooth devices if any other bluetooth devices(other Board2(PCA10028)) present it should connect.

2).if i send any data using ble_nus_string_send by board1 PCA10028 the other board2 should receive the data.

3).is there any example code in sdk for the above functionality.

please provide any example code.

Thankyou

Parents
  • Hi,

    The Nordic UART Service Client example should fit your needs. This example scans for devices that advertises with the NUS UUID in its advertisement report, and connects to the device. You can then transfer data between the boards using the Nordic UART service.

    You will have to modify the example if you want it to only connect to nRF51 devices, or if you want the central to be able to connect to multiple client-boards.

    [EDIT:]

    To extract name from advertising report, you can use a function like this:

        static bool get_name_from_adv_report(char *p_dev_name,
                            const ble_gap_evt_adv_report_t *p_adv_report)
    {
        uint32_t index = 0;
        uint8_t *p_data = (uint8_t *)p_adv_report->data;
        char *name;
        while (index < p_adv_report->dlen)
        {
            uint8_t field_length = p_data[index];
            uint8_t field_type   = p_data[index + 1];
    
        if ( (field_type == BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME )
           || (field_type == BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME)
           )
        {
            name =  (char *)&p_data[index + 2];
            name[field_length-1] = '\0';
            memcpy(p_dev_name,name, field_length);
            p_dev_name = name;
            return true;
        }
        index += field_length + 1;
    }
    return false;
    

    }

    You can then call this function in BLE_GAP_EVT_ADV_REPORT event and check the name agains what you have set as your target device name.

    Best regards, Jørgen

  • hi, i made my code peripheral to central

    1. if i turn on the the device it is connecting to what ever peripheral device is advertising.

    2)i want to restrict the central device only to connect with specified device name. how i can do this.

    3)if i send data from peripheral to central and displaying it in uart to termite(by pressing button (i handiled this button action)) it is working fine. unable to handle push button events in ble_app_uart_c example.

    4)where as if i send the data from central to peripheral it is only sending once after just connecting to the peripheral device. but by pressing button i am unable to send data using ble_nus_c_string_send().

Reply
  • hi, i made my code peripheral to central

    1. if i turn on the the device it is connecting to what ever peripheral device is advertising.

    2)i want to restrict the central device only to connect with specified device name. how i can do this.

    3)if i send data from peripheral to central and displaying it in uart to termite(by pressing button (i handiled this button action)) it is working fine. unable to handle push button events in ble_app_uart_c example.

    4)where as if i send the data from central to peripheral it is only sending once after just connecting to the peripheral device. but by pressing button i am unable to send data using ble_nus_c_string_send().

Children
No Data
Related