How to initiate BLE pairing manually

Hello,

I'm running nRF Connect SDK v1.9.0 on two nRF52840-DK devices, one Peripheral other Central.  
My application requires to initiate pairing, i.e. send pair request, programmatically.

For testing, I created a Peripheral device with a Service and two Characteristics.  
Via nRF Connect Desktop tool and nRF 52840 dongle, I can connect to that device, when connection establishes, it stays in "unencrypted link"  status.  
Then via Desktop tool, I click on "Pair" on the device settings configuration and it does pair with my Peripheral and gets into "encrypted link" mode. 
I want to accomplish same thing with my other nRF52840-DK device  which is in Central role.

Is there a way to initiate pair request manually ?   I couldn't see an API call for that.
All comments/hints are greatly appreciated.

E.
  • Thank you,  I did that, but overall pairing seems to be very unreliable.  Many times it fails with unspecified  reason.   

    But before that getting into details with pairing,  connections have been pretty undeterministic, too.    I have a Central which issues a connect to a Peripheral,  many times Central comes back with disconnected callback with reason  BT_HCI_ERR_CONN_FAIL_TO_ESTAB.   So,  do you have any recommendations to make connections more reliable ?  Any parameters to tweak ?   Why would it keep disconnecting with  BT_HCI_ERR_CONN_FAIL_TO_ESTAB reason ?

  • Hi,

    Could it be the environment you are testing this in? BT_HCI_ERR_CONN_FAIL_TO_ESTABLISH will happen from time to time. It means the peripheral did not respond to the connect request (only one request is sent per connect attempt) and that the central have to retry. It is normal for this error to happen from time time, but it can also occur quite frequently if there is lots of noise or interference from other nearby sources, for instance, active scanning from other BLE devices.

  • Yes, it is possible, however,  I repeat the test with another MCU vendor and I don't have these connection and pairing issues.   So, my question is,  what can I change to create a more robust connection and pairing operation ?   For example, is there more info on these parameters ?  How do they affect connections ?   : 

    /** Connection parameters for LE connections */
    struct bt_le_conn_param {
        uint16_t interval_min;
        uint16_t interval_max;
        uint16_t latency;
        uint16_t timeout;
    };
        .options = (_options), \
        .interval = (_interval), \
        .window = (_window), \
        .interval_coded = 0, \
        .window_coded = 0, \
        .timeout = 0, \
  • I don't think there is much you can do in FW to improve chances for a connection attempt to succeed  except for increasing the Radio's TX output power ( example ). Default is 0 dBm and radio is supporting up to +8 dBm. But I'm surprised you don't see this with the other board. Maybe the other board automatically repeats the connection attempt if it fails the first time? A Bluetooth sniffer trace may help show what the problem is.

    You are still using 2 Nordic DKs for this test?

  • I was using one Nordic nRF52840-DK in Peripheral mode and the other unit was another nRF52840-based module DK from another company.  So, I switched to two Nordic DKs and connection problems went away, so that's good.  But pairing failures are still here, so I've put Nordic nRF52840 dongle with Wireshark capture in between.   

    It seems like all is going well till when Slave responds with  LL_START_ENC_REQ and then I see all packets that are not empty PDU having "Encrypted packet decrypted incorrectly (bad MIC) " error.  

    Any idea why these bad MIC errors might be happening ? 

Related