CoreBluetooth Protocol Detection Time

This issue was discussed in October here . This is a new question, since CoreBluetooth is fairly new, and some changes may occur since then.

I have a BLE device ad every 2 seconds. Scanning starts with:

[self.CM scanForPeripheralsWithServices:nil options:0] 

Which most often returns (via centralManager didDiscoverPeripheral callback) after about 2-4 seconds. (CM is my CentralManger)

However, in approximately 30% of cases, scanning takes 10 to 18 seconds. WiFi and BT in neighboring devices were turned off to clear the spectrum as much as possible. Scan time is not related to RSSI. Which is -40 dB when next to the iPAd3, -70dB, about 5 meters in another room.

 [self.CM stopScan]; 

called before scanWithPeripherals, as this reduces the occurrence of really long wait times.

No connection is made. No feature or service data is requested. There is enough advertising data.

There is a useful TI demo application . This gives similar results (actually a bit worse, since it doesn't cause any stopScan calls)

The CBCentralManagerScanOptionAllowDuplicatesKey parameter, as shown in this https://stackoverflow.com/a/4646/2/2/2/2/2/5/01/2/2/2/2/2/5/01/9/01/... , if something seems to lengthen the detection time.

Obviously, the next step will be to use some of the more advanced BT noise / advertising reduction tools to further describe this CoreBluetooth answer.

This is another useful SO question , but not enough time to answer.

+7
source share
2 answers

CoreBluetooth is not listening continuously. He shares HW resources with the classic bluetooth and Wi-Fi.

Basically, you must be β€œLucky” to receive a proposal. "Lucky", since 2 sliding windows from two unsynchronized systems should touch each other. If CoreBluetooth opens this BLE window in 10% of cases, and you set the advertising interval without knowing the exact time, then it will / may take up to 10 times the advertising interval.

One recommendation is to advertise> fast <for the first 30 seconds (say 20 ms, and you should open it in the first active CoreBluetooth window), and then slow down the intervals specified by Apple. 2.00 seconds is NOT a good number.

See the manual here: https://developer.apple.com/hardwaredrivers/BluetoothDesignGuidelines.pdf

Page 18

Advertising Interval The advertising interval of a Bluetooth accessory should be carefully considered as it affects the time for discovery and connection. For a battery-powered accessory, its batteries must also be considered. To be detected by an Apple product, a Bluetooth accessory must first use a recommended advertisement interval of 20 ms for at least 30 seconds. If it is not detected within the first 30 seconds, select to save battery power and increase its advertising interval. Apple recommends using one of the following longer intervals to increase the chances of opening an Apple product:

645 ms 768 ms 961 ms 1065 ms 1294 ms

So, try 1294 ms if you need to save battery.

+10
source

Although this is an old thread, I see the same problem in macOS High Sierra 10.13.3 on my MacBook Pro (15 inches, 2017). The problem depends on the peripheral device, where the β€œApple TV” tends to always appear quickly, perhaps because it has a short advertising time. Some peripherals take a long time to appear or not to appear at all. In addition, if the advertisement is too slow, then the connection can also be slow, since the connection occurs by first detecting the advertisement and reacting to it in a very short fixed time (the peripheral device listens during this time).

I found a workaround for this problem that should disable BOTH Wi-Fi and Handoff. One disables Handoff by going to Apple - System Preferences - General and unchecking "Allow handoff between this Mac and your iCloud devices." Not only does this scan, the ad packets are detected faster and the connections are faster, it also shows a higher (less negative) RSSI, representing the stronger signal strength received.

Please note that the problem does not appear on iOS, possibly due to better support for BT and Wi-Fi, as well as between Handoff (Airdrop) and regular use of BLE. The problem, apparently, is one of the proportions of the BLE listening time during scanning and connection. Once the connection is established, there seems to be not much interference. This is partly due to the fact that after one connection there is an automatic repetition of low-level BLE repeats and an abrupt change in frequency between connection intervals. During scanning and establishing a connection (both of which depend on viewing the advertising packages), it is necessary to monitor 3 BLE advertising channels in sequence, but macOS behaves as if it is not done. Technically, advertising channels do not overlap with Wi-Fi channels (see http://www.argenox.com/a-ble-advertising-primer/ ).

0
source

All Articles