BLE connection to Android mobile phone

Hi,

I'm using NRF52840 to connect to an Android mobile phone.

The application scans for advertisement and when the NRF device starts advertising - connection is established.

The problem is that after bonding - connection isn't always established when advertising starts. Only when the application is open on Android mobile phone, everything works.

Is there any definition on NRF device that can solve that problem? To make sure the Android will connect on every advertisement after bonding?

Thanks!

Parents Reply Children
  • Still, you need to scan on Android, and when you get a scan result, you need to connect. Direct advertising has this advantage, that it's very fast, but lasts only for 1.25 sec after boot, so I understand it's good for quick reconnections. After that the device start advertising with a whitelist.

    On Android, you may call connectGatt method with autoConnect param set to true. This should keep make Android automatically reconnect if needed, but you cannot close the returned BluetoothGatt object. So for a long running operation you'd have to have a foreground service that holds this object and awaits connection. In practice, on Android 8+ it's better to scan using a PendingIntent with correct filter. You don't need to have the service in that case and your app can be even killed. When the device is scanner, you'll get the Intent which can launch BroadcastReceiver, or a Service, from which you may promote the serivce to foreground and connect to the device with autoConnect  = true.

    Actually, we should do such sample, as it's quite common. I'll add it to our backlog.

  • The address is saved on the device side in whitelist butter, yes. But I'm completely not an expert when it comes to embedded, so I don't know how it's done. Perhaps automatic by the peer manager.

Related