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.

Parents
  • Hi,

    1. It looks like the HR peripheral terminates the connection shortly after it has rejected the pairing request, but it's not clear why it's rejected and why it disconnects, unfortunately. As a test, could you  try to comment the call to  pm_conn_secure() in your app to see if the same happens if the central doesn't initiate pairing? It would also be nice to know if the disconnect occurs if you connect with the nRF connect app on Android or iOS.

    2. It's possible to set the Scanning Module with multiple filters and configure it to only raise the NRF_BLE_SCAN_EVT_FILTER_MATCH event when all filters match. You can also check which filters matched in the nrf_ble_scan_filter_match event structure passed to NRF_BLE_SCAN_EVT_FILTER_MATCH event.

    3. You can run BLE scanning and ANT rx concurrently. The Softdevice will handle scheduling of radio time for each protocol.

    Best regards,

    Vidar

  • Thank you very much!
    Commenting pm_conn_secure() in Heart Rate Collector Handler solved my problem, works perfectly. Any thoughts why is that so? Can it be that maybe my belt somehow doesn't support encryption (pairing/bonding)? My belt is BT4.0.

    EDIT: I have tried pairing my belt with my PC app and it pairs there.

  • I don't recall seeing any issues similar to this before. Could you try to disable the SEC_PARAM_LESC bit in your app and try to uncomment the pm_conn_secure() line again? Maybe the belt only accepts legacy pairing requests for some reason. You may also want to erase any existing bonds on the device before testing. You can to so be keeping button 3 pressed on boot.

    A couple of Sniffer traces showing the differences between the pairing request sent by the PC app and your central might also give us a clue as to why the pairing gets rejected in your case (nRF Sniffer for Bluetooth LE). 

  • Sorry for my very late respond, I've been playing around with nRF.
    Unfortunately after tests I am still not able to sustain pairing with HR. Although I have noticed that sometimes I receive one heart rate value before disconnection - if this somehow helps here.

    Anyway, for now I will develop without HR, and later get some Sniffers. Thank you for your help.

  • No worries. It's a bit difficult to say what may be causing the HR belt to disconnect when pairing is enabled, but is it an option to simply disable pairing support (i.e. comment the pm_conn_secure() call again)?

  • 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

Reply
  • 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

Children
No Data
Related