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

Having Android reconnect to a bonded peripheral without user interaction

I've read the Robin Heydon book and bits of the Core 4.0 spec and I'm still confused as to how an Android phone with my app installed is supposed to reconnect to my peripheral to which is has previously connected and bonded.

Suppose my peripheral is a device designed to detect the presence of its owner, who is always carrying their mobile phone and that phone is always switched on, but may be in standby mode. Suppose the mobile is running Android 4.4 or later.

The Android BLE API Guide is quite clear about the initial connection: doing an LE scan, connecting to the GATT server, discovering services, etc. But it says nothing about subsequent reconnections and very little about bonding in the context of LE.

In order for a connection to be established, the peripheral has to be advertising and the central has to be scanning. My peripheral is an nRF51822 and I can have it advertise at the right times, no problem there. But if the central is an Android phone, when does it scan?

Does it only scan when I programatically call startLeScan() in my app code? I don't think this is the case - I've seen a reconnection happen without that.

Is there a background process running on Android that is always scanning for devices to which it has previously bonded? That also doesn't seem to be the case, at least not reliably - reconnection happens for a few hours after I've programmatically scanned but within a day or so it's stopped, I think.

(Using the Sniffer and Wireshark is of limited use here. Since it's scanning I'm interested in, there's nothing to see on the air because a scan is just RX. There's the scan request and response to see afterwards, but I'm more interested in when Android is doing the bit before that, the RX bit.)

Parents Reply Children
No Data
Related