Home > Net >  How often does Android/iOS send out BT/BLE connect packets?
How often does Android/iOS send out BT/BLE connect packets?

Time:02-03

I found that on Android, after calling connect() on a Bluetooth device, the OS will try to connect for ~30 seconds before timing out. My question is how often does Android send out connect packets during this 30 second window? Is this phone manufacturer dependent?

I'm wondering what would be the minimal amount of time for a BLE device to have to wait for a connection before stopping advertising/going back to sleep.

Is this similar/the same on iOS?

CodePudding user response:

It does not really work like that, i.e. that the central periodically sends out "connection packets" until it succeeds. It's rather the other way around. The peripheral sends out advertisement messages frequently, configured by the advertisement interval, usually somewhere between 20 ms and 1 second, depending on how long the manufacturer wants the battery to last. The central then periodically scans, meaning it keeps its radio on listening for advertisements for some time before going to sleep, before it starts listening again. If it detects an advertisement packet containing a sender address it wants to connect to, it replies immediately with a CONNECT_IND packet, telling the peripheral "you are now connected". The scan interval and scan window parameters that the Host OS can set (like Android) are typically something like 60 ms window and 1 sec interval when you use autoConnect=true (i.e. background connection without timeout) in Android. If you set autoConnect to false, which also imposes a timeout of 30 seconds, you get something like 30 ms scan window with a 60 ms interval. The duty cycle of the scanning directly increases the probability it will find an advertisement packet to connect to. The same for the advertisement interval. For iOS, there are never any time outs when connecting, but instead when you call connect, it will use a good duty cycle for the scanning and after some time it will start to use a worse duty cycle, to save battery if it doesn't connect instantly.

At a peripheral, the programmer of it can implement a timeout to stop advertising after a while if no central connects, if that is desired. It is up to the programmer how long time it should wait in that case. If the lowest possible advertisement interval is used (20 ms), then it is usually enough with a few seconds in order to connect, assuming the central is scanning.

  • Related