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

Struggling to pair with SDK and peripherials.

Hi!
Recently I have been working with Nordic products, starting with NRF52DK. I want to pair/bond cycling equipment (BLE and ANT+) with NRF52DK. After no success with ANT+ SDK examples I decided to deep into BLE first (ble_app_hrs_c_pca10040_s332). I have some problems during that:
1. I can't sustain connection with hear rate belt. Everytime I try to connect with it I get following result:

<info> app: Device: Heart rate belt                                             
<info> app: name: 2809_83C5AB                                                   
<info> app: Connected.                                                          
<info> app: GATT ATT MTU on connection 0x0 changed to 23.                       
<info> app: Data length for connection 0x0 updated to 27.                       
<info> peer_manager_handler: Connection security failed: role: Central, conn_han
dle: 0x0, procedure: Pairing, error: 133                                        
<info> app: BLE_GAP_EVT_AUTH_STATUS: status=0x85 bond=0x0 lv4: 0 kdist_own:0x0 k
dist_peer:0x0                                                                   
<info> app: Disconnected, reason 0x13.                                          
<info> app: Starting scan. 

As far I know this error relates to BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, but I have no idea how to solve it. I have tried few options for Peer Manager but with no success. I changed #define TARGET_UUID that describes cadence and speed sensor and I did manage to connect without any problems.
2. I am reading event NRF_BLE_SCAN_EVT_FILTER_MATCH from scan module, and I perform additional check if this is really a HeartRateService. In future I want to make a list of device types in range so I need to read what UUID has coused scan event trigger. As you can see below I am reading 16bit UUID from advertising data, next check if this is HeartRateService and also read device name. Can it be done somehow faster? Since scan event has been triggered and I am filtering by UUID, UUID that has triggered the event has to be stored somewhere. Is there an option to read what UUID/DeviceName etc. coused event NRF_BLE_SCAN_EVT_FILTER_MATCH in scan module? By that I wouldn't need to scan advertising buffer for specific data.

/*Check for UUID*/
    length = ble_advdata_search(p_adv_report->data.p_data, p_adv_report->data.len, &offset, BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE);
    if (length == 0) {
        length = ble_advdata_search(p_adv_report->data.p_data, p_adv_report->data.len, &offset, BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE);
    }
    
    if (length != 0) 
    {   
        memcpy(device, &p_adv_report->data.p_data[offset], 2);
         /*If this is Hear Rate Service*/
        if(device[0] == 0x0D && device[1] == 0x18)
        {
            NRF_LOG_INFO("Device: Heart rate belt");
            /*Print device name*/
            offset = 0;
            length = ble_advdata_search(p_adv_report->data.p_data, p_adv_report->data.len, &offset, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME);
            if (length == 0) {
                // Look for the short local name if it was not found as complete.
                length = ble_advdata_search(p_adv_report->data.p_data, p_adv_report->data.len, &offset, BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME);
            }

            if (length != 0) {
                memcpy(name, &p_adv_report->data.p_data[offset], length);
                NRF_LOG_INFO("name: %s", nrf_log_push(name));
            }
            /*Perform connection*/
            sd_ble_gap_connect(p_addr, p_scan_params,  p_conn_params, con_cfg_tag);

        }
    }

3. If I need to scan for BLE and ANT devices that are nerby can it be done in one operation or I need to first scan for BLE and then for ANT.

  • fter day of tests I come to conclusion that either I do something wrong while configuring SDK or these cheap Aliexpress sensors (Magene/Kyto) does not support pairing at all. Few posts earlier I said that cycling&cadence sensor pairs well with nRF which is not true. It turns out that it does not allow pairing too.
    I have edited RCSC_C SDK example to CSCS_C. Also had to increase PM_FLASH_BUFFERS to 32 and now I get these logs:

    <info> app: Starting scan.                                                                 
    <info> app: Running Speed and Cadence Service discovered.                                  
    <info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, p
    rocedure: Pairing, error: 133                                                              
    <warning> peer_manager_handler: Disconnecting conn_handle 0.                               
    Speed kmh: 21.5    RPM: 167  Revs: 71  Time: 25369                            
    Return ID: FFFF                                                                
    <info> app: Disconnected. conn_handle: 0x0, reaso 0x0, reason: 0x16  

    So it is the same error as with HR belt. I get 0x16 since SDK shuts down connection after failed pairing. When I don't do that, sensor stays connected and I can collect data.
    When I use Bluetooth LE Explorer or TrainerRoad both apps say that pairing was successful, but I can't tell if it isn't just connected. For now I don't have any certified sensors, but maybe someone could test attached code with your own equipment? I would be pleased to see results. 
    Sensors_test.zip
    ble_cscs_c.zip

Related