Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Unable to Connect on Android After Connecting Via Bluetooth Device List

We have been having a persistent issue with customers that have Android phones.  Our product uses the nRF SDK and we have a iPhone and Android Web app that is based on Cordova and Ionic.

We connect to our product within the our app without issue.  The problem is sometimes customers go to their Bluetooth Device list on their Android phone and try and connect to our product that way as it appears in the list of devices.  Once this happens then our app can no longer connect to the device on that phone without reseting the networking settings of that phone.  This doesn't happen with iPhones as our product never shows up in the Bluetooth Devices List.

Is it normal for the BLE devices to show in the Bluetooth Devices List on Android devices?  Is there a way to stop it showing up in that list or something else I can do so that it won't allow customers to try and connect that way?

Thanks,

Parents
  • Hello ,

    When a user tries to connect to a device from Android Bluetooth settings, the phone will start bonding with the device, just as if you'd call "createBond" method. Do you support bonding in your firmware?

    The Android Settings app can connect and bond to any device, but if it does not support it, it will disconnect afterwards. For example, HID devices are supported natively, so Android will keep and use the connection, but HRM device is not, so after bonding and service discovery Android would simply disconnect. During bonding, some other app may get an event that a device has connected, and it may also connect to it using "connectGatt" method. In that case, the physical connection will not be terminated, as at least one client on the phone is using it.

    As far as I understand, in your app you may be doing something like:

    1. not using bonding, but the device does not reject pairing request - if bonding implementation is not correct, this may cause troubles accessing some services.

    2. storing the device address for the future - if the device got connected and bonded from another app (settings), your app was not involved in scanning and establishing connection, so you'd have to fix something on your side to support that case as well (e.g. receiving bonded devices or connected devices from bluetooth manager).

    3. the device may still be connected to the phone while you're trying to scan for it, so it does not appear on scan results - you need to show connected/bonded devices in your app (unfortunately, you can't filter only those that have required services, like you could on iOS).

    Do you support bonding on the device? How does your device behave when bonded? What is the difference when connected from your app and from the Android Settings?

    Could you also say what do you mean by "reseting the networking settings of that phone."?

    Best Regards,

    Aleksander

  • Hi  ,

    Thank you for the detailed post.  No, we don't support bonding in our device.  To your point 1, no our app also doesn't use bonding nor does our device doesn't reject pairing requests.  

    This project uses nRF52 SDK 16.0.0.  Is there some nRF SDK examples of rejecting pairing?  

    Best Regards,

    Darren

  • I have no idea. But I'm sure  knows even poems about nRF5 settings, so I'll leave it to him! Good luck!

Reply Children
  • Thank you Aleksander!

    I missed the last reply and didn't notice the ball was in my court. 

    Unsure if any of the examples in the SDK demonstrate this. 

    Your application could call sd_ble_gap_sec_params_reply() stating pairing is not supported. 

    You can find more information here: 
    How to Respond with pairing unsupported 

    Br, 
    Joakim

  • Thank you Joakim,

    I tried what you suggested but I don't think it is working as I say the following in the RTT log.

    <info> peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
    
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Bonding data, action: Update
    
    <info> app: FDS Evt: 1 rxd SUCCESS
    
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Peer rank, action: Update
    
    <info> app: FDS Evt: 1 rxd SUCCESS
    
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    
    <info> app: FDS Evt: 1 rxd SUCCESS
    
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Central address resolution, action: Update
    
    <info> app: FDS Evt: 1 rxd SUCCESS
    
    <info> peer_manager_handler: Peer data updated in flash: peer_id: 0, data_id: Local database, action: Update
    
    <info> app: FDS Evt: 2 rxd SUCCESS

    I have the following `sec_param` set 

    #define SEC_PARAM_BOND 1     /**< Perform bonding. */
    #define SEC_PARAM_MITM 0     /**< Man In The Middle protection not required. */
    #define SEC_PARAM_LESC 0     /**< LE Secure Connections not enabled. */
    #define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE /**< No I/O capabilities. */
    #define SEC_PARAM_OOB 0                                /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE 7                       /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE 16                      /**< Maximum encryption key size. */

    Should I set `SEC_PARAM_BOND` to `0`?  As we don't support bonding.

    Thanks,

  •  

    I have been doing some additional troubleshooting on this issue with an Android tablet.  I have set

    SEC_PARAM_BOND to 0 and

      sec_param.kdist_own.enc = 0;
      sec_param.kdist_own.id = 0;
      sec_param.kdist_peer.enc = 0;
      sec_param.kdist_peer.id = 0;

    When I initiate a connection to our device with our custom app or nRF Connect for Android I get a pop up asking to Pair.  How can I stop this?   
    Note: I need to continue to support Nordic DFU via BLE. 
    Here is the log from nRF Connect.
    nRF Connect, 2022-10-31
    M8-FD0F534C8F85D3BB (FE:6A:A2:A9:78:63)
    V	11:49:56.567	Connecting to FE:6A:A2:A9:78:63...
    D	11:49:56.567	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
    D	11:49:57.556	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
    D	11:49:57.584	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
    I	11:49:57.584	Connected to FE:6A:A2:A9:78:63
    V	11:49:57.585	Discovering services...
    D	11:49:57.585	gatt.discoverServices()
    D	11:49:57.676	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
    D	11:49:57.725	[Broadcast] Action received: android.bluetooth.device.action.PAIRING_REQUEST, pairing variant: PAIRING_VARIANT_CONSENT (3)
    I	11:49:58.200	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
    D	11:49:58.715	[Callback] Services discovered with status: 0
    I	11:49:58.715	Services discovered
    V	11:49:58.760	Generic Access (0x1800)
    - Device Name [R W] (0x2A00)
    - Appearance [R] (0x2A01)
    - Peripheral Preferred Connection Parameters [R] (0x2A04)
    - Central Address Resolution [R] (0x2AA6)
    Generic Attribute (0x1801)
    - Service Changed [I] (0x2A05)
       Client Characteristic Configuration (0x2902)
    Unknown Service (bdb70001-202b-11ea-a5e8-2e728ce88125)
    - Unknown Characteristic [N R] (bdb70002-202b-11ea-a5e8-2e728ce88125)
       Client Characteristic Configuration (0x2902)
    - Unknown Characteristic [N R] (bdb70003-202b-11ea-a5e8-2e728ce88125)
       Client Characteristic Configuration (0x2902)
    - Unknown Characteristic [N W] (bdb70004-202b-11ea-a5e8-2e728ce88125)
       Client Characteristic Configuration (0x2902)
    Device Information (0x180A)
    - Manufacturer Name String [R] (0x2A29)
    - Model Number String [R] (0x2A24)
    - Serial Number String [R] (0x2A25)
    - Hardware Revision String [R] (0x2A27)
    - Firmware Revision String [R] (0x2A26)
    - Software Revision String [R] (0x2A28)
    Nordic UART Service (6e400001-b5a3-f393-e0a9-e50e24dcca9e)
    - RX Characteristic [W WNR] (6e400002-b5a3-f393-e0a9-e50e24dcca9e)
    - TX Characteristic [N] (6e400003-b5a3-f393-e0a9-e50e24dcca9e)
       Client Characteristic Configuration (0x2902)
    Secure DFU Service (0xFE59)
    - Buttonless DFU [I W] (8ec90003-f315-4f60-9fb8-838830daea50)
       Client Characteristic Configuration (0x2902)
    D	11:49:58.761	gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
    D	11:49:58.766	gatt.setCharacteristicNotification(bdb70002-202b-11ea-a5e8-2e728ce88125, true)
    D	11:49:58.768	gatt.setCharacteristicNotification(bdb70003-202b-11ea-a5e8-2e728ce88125, true)
    D	11:49:58.769	gatt.setCharacteristicNotification(bdb70004-202b-11ea-a5e8-2e728ce88125, true)
    D	11:49:58.771	gatt.setCharacteristicNotification(6e400003-b5a3-f393-e0a9-e50e24dcca9e, true)
    I	11:49:58.774	Connection parameters updated (interval: 48.75ms, latency: 0, timeout: 5000ms)
    I	11:50:03.115	Connection parameters updated (interval: 198.75ms, latency: 0, timeout: 4000ms)
    D	11:50:03.620	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_NONE (10)
    I	11:50:03.620	Bonding failed
    D	11:50:06.585	[Callback] Connection state changed with status: 22 and new state: DISCONNECTED (0)
    E	11:50:06.585	Error 22 (0x16): GATT CONN TERMINATE LOCAL HOST
    I	11:50:06.585	Disconnected
    D	11:50:06.819	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED
    
  • Hi!

    WestCoastDaz said:
    When I initiate a connection to our device with our custom app or nRF Connect for Android I get a pop up asking to Pair.  How can I stop this?

    Not quite sure how to stop this pairing window to appear, if possible.

    I'll ask around for someone with more experience on this particular topic. Let me get back to you.

    Br, 
    Joakim

  •  

    Just checking in to see if you had a chance to look into this further?

    Thanks,

    Darren

Related