Thanks, Joakim. Exactly the kind of info I was after!
We're setting up a very simple test environment to determine which advertising interval to use. The test peripheral will start advertising itself at 150ms for 60s, then 149ms for 60s, etc. all the way down to 20ms, and we'll use the results to figure out which advertising interval works best for us. (Our goals are the following: maximize iPhone battery life, maximize peripheral battery life, and minimize discovery time in the background without user/peripheral interaction.)
A couple follow up questions for you:
1) After we identify a good advertising interval, how likely is it that it might not be "good" in the future due to iOS software changes? We want to avoid selecting a short term solution.
2) It sounds like 20ms will be our safest bet but there might be other intervals that also work well. Can you talk a bit about the theory around this?
Thanks, Sam
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
|