Hi Sam,
You are bringing up an interesting topic and we have done some interesting work in this area. To start with, when the App goes in the background, the scanning parameters are changed in order to reduce power consumption. We had to find a balance between performance and power consumption while the phone is in standby mode.
Since the phone is scanning with a low duty cycle, the peripheral will have to go the extra mile and advertise more often. It ends up being a statistical problem. We have done simulations on this and the results provide us with some guidance. We see that the median discovery time when the phone is in standby is about 60 times the advertising interval. The 95-percentile discovery time when the phone is in standby mode is about 300 times the advertising interval. Meaning, if the peripheral advertise every 20 ms an iPhone in standby mode would discovery it within 6 seconds with a 95 percent probability. As you have discovered, there are some advertising interval that works better than others (we can go into the theory around this in a separate discussion).
Please note that the numbers given above are for what we consider normal RF conditions with some minor interference. The performance may get drastically worse in an environment with lots of interference leading to excessive packet loss.
We do recommend that a peripheral that wants to be detected by an iPhone in standby mode should advertise every 20 ms for best performance.
Thanks, Joakim
On Apr 24, 2012, at 7:32 PM, Sam Kirchmeier wrote: Hi, all. Working on an app where we're scanning for BLE peripherals in the background.
We have a proof of concept app up and running, but we're seeing some long, seemingly random times between when the app goes into the background and when a peripheral is discovered. Our goal is to minimize discovery time when the app is running in the background.
We've tried various advertising rates on the peripheral side. Even when we advertise every 20ms, we see occasional 4-5 second delays until the peripheral is discovered.
When the peripheral advertises itself every 50ms, we've seen delays as long as 30 seconds before discovery. (Delays vary from 1 second to 30 seconds.)
Anyone else seeing this kind of behavior? Does iOS randomize or sleep between BLE scans in the background? Any insight would be helpful.
Thanks, Sam
|