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

  • 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, thank you for responding. i have a code which is nrf_adc_example which is peripheral. i want to make it as central. how i can change the code peripheral to central otherwise peripheral to both peripheral and central.

  • Which softdevice are you using? S130 can work as both central and peripheral concurrently. In many cases it will be easier to start off with a central example and add your functionality to the this, instead of changing your existing code from peripheral to central. Have a look at the differences of the main files of ble_app_uart (peripheral) and ble_app_uart_c (central). The peripheral starts advertising while the central starts scanning.

  • i am using S130 i made so many changes in that ADC example which is peripheral. i need to change it as central now. not possible to again restart the changes with central application.

  • Then you need to change your main-file to use scanning instead of advertising, and implement the relevant handler functions. See the above mentioned examples for how this is done. I also recommend that you read the BLE central tutorial to understand the various parts. You also have to edit the CENTRAL_LINK_COUNT and PERIPHERAL_LINK_COUNT parameters, and set the corresponding required RAM settings.

Related