Reputation: 1165
The time taken to connect my app to a Bluetooth 4.0 device seems to vary quite a bit. Same app, same device. Sometimes it connects immediately - like less than a second. Sometimes it takes about 10-12 seconds. And once in while it doesn't connect at all - I need to restart the scan, etc. I was wondering if anyone else has seen this issue. What could be causing this?
Upvotes: 1
Views: 857
Reputation: 947
I am also finding the same issue. I have a BLE device advertising every 2 seconds.
[self.CM scanForPeripheralsWithServices:nil options:0]
returns after 0.2s to ~30s. (CM is my CentralManger)
My next step is to collect the times in a CSV file and plot the frequency distribution of the various connect times and connect times versus time, to see if I can discern a pattern.
There is a useful TI demonstrator app. But annoyingly they have made it universal and not implemented the iPad storyboard (it is there and blank), and setting it to iPhone only version is causing an error when I try to run in debug mode. And I don't have another Apple device with BLE to hand.
Calling
[self.CM stopScan];
before the scanWithPeripherals seems to reduce the occurrence of really long waits.
I tried the CBCentralManagerScanOptionAllowDuplicatesKey option as seen in this Stackoverflow answer but if anything that seemed to lengthen discovery times.
I think I will get hold of some Bluetooth packet sniffer tools to help with seeing what is actually in the air.
Upvotes: 1
Reputation: 3084
There can be a number of reasons for this. Here are a few off of the top of my head.
The device is not advertising very often. The O/S basically scans for a device that is sending out an advertising signal. This is something the devices do as infrequently as possible to save battery power. Some devices have a button that causes them to advertise more frequently when you are setting up a connection. Others may have a setting that allows you to change the advertising rate. (What device are you using?)
The device may be connected to something else.
The battery may be low.
There could be radio interference from another source. WiFi is frequently an issue. Both Bluetooth 4.0 and WiFi devices use frequency hopping. Try turning off or restarting the WiFi network. Try turning off WiFi on the phone and see if that helps any.
Of course, while we hate to admit it, there's always that lurking possibility that we coded something wrong in our app! The fact that we got one connection is no guarantee that the app is perfect.
Upvotes: 1