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

  • 1/2: Then you need to have the name of the device in the advertising data and extract and compare this to your target device name on every BLE_GAP_EVT_ADV_REPORT event in your BLE event handler.

    I have added an example function that can extract the name in my original example above.

    3/4: Can you try to explain your problem in another way? I don't understand what you mean.

Reply Children
No Data
Related