Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to discover BLE peripheral service faster?
    text
    copied!<p>I find that my implementation of the BLE protocol in iOS7 to be very slow in the start up phase. The startup sequence amounts to ~68% of the whole execution time in my app.</p> <p>What can I do to make it faster?</p> <p>I've timed it, and here's what I get.</p> <pre><code> t dt 37.598 [BLE] Discovered peripheral at RSSI -27 with UUID:XYZ 37.599 0.001 [BLE] Connecting to peripheral 37.602 0.003 [BLE] Scanning stopped 37.685 0.083 [BLE] Peripheral connected 38.48 0.795 [BLE] Discovered service 38.599 0.119 [BLE] Discovered characteristic </code></pre> <p>As you can see there's a huge bottle neck before discovering the service.</p> <p>My startup code simplified:</p> <pre><code>- (void)centralManagerDidUpdateState:(CBCentralManager *)central { switch (central.state) { case CBCentralManagerStatePoweredOn: [central scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:kServiceUuid]] options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @YES}]; break; case CBCentralManagerStatePoweredOff: [central stopScan]; break; default: break; } } - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { if (self.discoveredPeripheral != peripheral) { self.discoveredPeripheral = peripheral; // Save a local copy of the peripheral, so CoreBluetooth doesn't get rid of it [central connectPeripheral:peripheral options:nil]; [central stopScan]; } } - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { [peripheral discoverServices:@[[CBUUID UUIDWithString:kServiceUuid]]]; } - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error { for (CBService *service in peripheral.services) { [peripheral discoverCharacteristics:@[array of characteristics] forService:service]; } } - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { ... } </code></pre> <p><strong>EDIT</strong></p> <p>I've learned that similar apps on Android does this ten times faster (making the Android app feel snappier -> better user experience) so I'm curious if it's my implementation, BLE layer or hardware that's the bottleneck. It's tested on an iPhone 4S.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload