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

Issue: unable to connect to device from stored Bluetooth address

Hello, I'm using nrf52832, SDK 15 e softdevice 6.0.

Smartphone with issue has Android 9 or 10 and Bluetooth 5. Instead, all works fine with smartphone with Bluetooth 4.2

Smartphone used:
Samsung Galaxy S10+
Xiaomi Redmi Note 7
Huawei P30
Xiaomi mi 8

After the first scan, we store the device address of the selected device for connection. We perform the connection and all works fine. If we close the app and reconnect to device, all works fine.

But, if we reboot the smartphone and try to connect to address stored, the connection FAILS. Ever!

The only way to unlock from this, is to turn off and on the smartphone Bluetooth.

We found a workaround that works: perform scan before the connection and never use stored address.

This is the method used for connection:

mBluetoothGatt = myDevice.connectGatt(context, false, mGattCallback, BluetoothDevice.TRANSPORT_LE);

 

This is the Log after reboot: the connection fails

2020-04-03 13:13:58.500 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:13:58.501 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:13:58.501 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: could not find callback wrapper

2020-04-03 13:13:58.501 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:13:58.503 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: connect() - device: D9:B4:0A:DA:C8:9F, auto: false

2020-04-03 13:13:58.503 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: isSecureModeEnabled

2020-04-03 13:13:58.503 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: registerApp()

2020-04-03 13:13:58.503 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: registerApp() - UUID=16f3dcb6-ba5a-44bf-ad7b-c0da5beeb14c

2020-04-03 13:13:58.505 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onClientRegistered() - status=0 clientIf=12

2020-04-03 13:14:03.513 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=12 device=D9:B4:0A:DA:C8:9F

2020-04-03 13:14:03.518 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: isSecureModeEnabled

 

2020-04-03 13:14:31.554 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:14:31.555 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:14:31.556 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: could not find callback wrapper

2020-04-03 13:14:31.556 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: cancelOpen() - device: D9:B4:0A:DA:C8:9F

2020-04-03 13:14:31.568 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: close()

2020-04-03 13:14:31.573 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: unregisterApp() - mClientIf=12

2020-04-03 13:15:08.042 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: onBluetoothStateChange: up=false

2020-04-03 13:15:08.042 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: Bluetooth is turned off, stop adv

2020-04-03 13:15:08.042 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: There are no active google scan apps, stop scan

2020-04-03 13:15:08.042 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: stopAllScan standalone boolean value is = false

2020-04-03 13:15:08.042 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: Exiting stopping all callback scans

2020-04-03 13:15:08.066 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: ondisableBLE

2020-04-03 13:15:08.066 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: There are no active google scan apps, stop scan

2020-04-03 13:15:08.066 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: stopAllScan standalone boolean value is = false

2020-04-03 13:15:08.066 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: Exiting stopping all callback scans

2020-04-03 13:15:08.227 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: onBluetoothStateChange: up=true

2020-04-03 13:15:08.227 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: onBluetoothStateChange: Bluetooth is on

2020-04-03 13:15:08.390 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:15:08.391 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:15:08.391 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: could not find callback wrapper

2020-04-03 13:15:08.392 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:15:08.393 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:15:08.393 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: could not find callback wrapper

 

This is the log after Bluetooth restarting: the connection works fine

2020-04-03 13:16:21.462 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:16:21.464 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:16:21.464 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: could not find callback wrapper

2020-04-03 13:16:21.465 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:16:21.467 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: connect() - device: D9:B4:0A:DA:C8:9F, auto: false

2020-04-03 13:16:21.467 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: isSecureModeEnabled

2020-04-03 13:16:21.467 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: registerApp()

2020-04-03 13:16:21.467 27399-27399/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: registerApp() - UUID=96ae62dc-4728-4bd0-8f54-e6e67542c1d8

2020-04-03 13:16:21.469 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onClientRegistered() - status=0 clientIf=12

2020-04-03 13:16:22.425 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=12 device=D9:B4:0A:DA:C8:9F

2020-04-03 13:16:22.436 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: discoverServices() - device: D9:B4:0A:DA:C8:9F

2020-04-03 13:16:22.975 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onConnectionUpdated() - Device=D9:B4:0A:DA:C8:9F interval=6 latency=0 timeout=500 status=0

2020-04-03 13:16:23.244 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onSearchComplete() = Device=D9:B4:0A:DA:C8:9F Status=0

2020-04-03 13:16:23.351 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: setCharacteristicNotification() - uuid: 7d32c0f0-bef5-11e3-b1b6-0800200c9a66 enable: true

2020-04-03 13:16:23.456 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onConnectionUpdated() - Device=D9:B4:0A:DA:C8:9F interval=28 latency=0 timeout=500 status=0

2020-04-03 13:16:23.615 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:16:23.616 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothAdapter: STATE_ON

2020-04-03 13:16:23.616 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothLeScanner: could not find callback wrapper

2020-04-03 13:16:27.673 27399-27420/com.spirometry.spirobanksmartsdksample D/BluetoothGatt: onConnectionUpdated() - Device=D9:B4:0A:DA:C8:9F interval=12 latency=0 timeout=400 status=0

Parents
  • Hello,

    is there a Nordic support engineer to assign to this ticket?

    Thanks

  • Hello,

    The phone is the central, and the nRF the peripheral, right?

    Can you try to capture a sniffer trace for the advertiser? Does it look like there are any connection requests from the phone when it doesn't connect?

    Do you do anything to the peripheral when you reboot the Bluetooth on the phone so that it connects again? Or was the peripheral advertising all the time?

    On the mobile phone side, are you using any Android libraries from Nordic?

    What does onClientConnectionState() - status=133 mean? What function returns this status, and does it say in the header file for that function what this status means?

    Best regards,

    Edvin

  • Hello,

    yes the nRF is the peripheral. I don't have a sniffer and the peripheral advertising all the time.

    i'm using standard Android libraries API 29. What is Android libraries from Nordic?

    133 is a generic error returned by the callback onClientConenctionState() of the function BluetoothGatt:conenct().

    Why am I forced to retry a scan if I reboot the phone to be able to connect? Even if I already know the connection address?

    Best regards

  • Hello,

     

    mdido said:
    Why am I forced to retry a scan if I reboot the phone to be able to connect? Even if I already know the connection address?

     That I am not sure of. You can possibly try to bond with the device, to see if that works. I guess it is not a common use case to try to connect without scanning to see whether the device is advertising first. You would have to look this up in an Android forum.

     

    mdido said:
    What is Android libraries from Nordic?

     We don't have any generic android libraries, but there are some DFU libraries for Android (and iOS), but these won't make a change in this case.

     

    mdido said:
    I don't have a sniffer and the peripheral advertising all the time.

     No need for this. I just wanted to check if the device was advertising, but there is no reason to believe something else if you do not reset the nRF at the same time as you reset your phone's Bluetooth.

    I am not familiar with Android's BLE libraries, but I found this site:
    https://stackoverflow.com/questions/32886725/android-4-4-bluetooth-low-energy-connect-without-scanning-for-a-ble-device

    I am not sure, but I guess that there is something that isn't initialized properly unless you scan, or you need some more parameters than the address to connect from an Android.

    In theory, it is possible to connect only based on the BLE address. If you use the Softdevice from Nordic in your BLE central, this is in fact possible. But I don't know how this works in the Android libraries. I am sorry.

    For debugging purposes, you could of course try to start the scan, and stop it on the first advertising report. It would be interresting to know whether you can connect to the known device without having received an advertisement packet from that device. It would give some pointers to whether it is something that isn't initialized, or if you are missing some required information from the peripheral device. However, whatever outcome you get from that test, I wouldn't know how to treat that answer in the Android BLE stack.

    Best regards,

    Edvin

  • Hello,

    thanks for your answer.

    I tried the test you asked for, if I stop the scan before you find the device it doesn't work.

    Is there anyone on the Nordic team who is an Android expert? I ak that because I don't have this problem if I use the Qualcomm chip CSR1010. And I'd like understand why it happens with the nrf52832 instead

  • Hello,

    I spoke with our mobile apps developer team. They said that as long as the device is advertising with a public address, you may connect without scanning.If not, you have to scan before connecting, even if you know the address. Turning off/on the phone/bluetooth will clear all of this information, so you need to scan before connecting. The exception is if you use bonding. Then all the data necessary to bond with the device is stored in the phone, and not deleted when you turn off/on the phone/bluetooth.

    Best regards,

    Edvin

  • Hello,

    thank you for the support. Now it's everything clear.

    For the firmware on the device nrf52 I started from the example "ble_app_uart". In this example the bonding is not activated. How do I insert/activate it? Is there a tutorial? I am using the segger embedded studio as development system.

    Best Regards

Reply Children
Related