5

Following connection to a BLE device which is advertising a specific service I'm interested in, in order to discover this service, I'm calling:

[self.peripheral discoverServices:@[[self.class serviceUUID]]];

The - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error delegate method gets called with no error, yet the number of services returned for the peripheral is 0, and therefore no characteristics are further discovered. Does anyone have any idea why this is happening? Thanks in advance!

Below is the full body of the delegate method.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
    if (error) {
        NSLog(@"didDiscoverServices failed: %@", error);
        return;
    }

    NSLog(@"didDiscoverServices succeeded for peripheral: %@.", peripheral.name);
    NSLog(@"Number of services: %d", peripheral.services.count);

    for (CBService *s in peripheral.services) {
        NSLog (@"Discovered service UUID: %@", s.UUID);
        if ([s.UUID isEqual:[self.class serviceUUID]]) {
            NSLog(@"Discover characteristics...");
            [self.peripheral discoverCharacteristics:@[[self.class controlPointCharacteristicUUID], [self.class packetCharacteristicUUID]] forService:s];
        }
    }
}

The console shows:

2014-11-27 15:54:51.933 k[197:13362] didDiscoverServices succeeded for peripheral: BootK
2014-11-27 15:54:51.934 k[197:13362] Number of services: 0
Gina
  • 89
  • 6
  • 2
    What is your peripheral? Have you tried something like the LightBlue app from the app store to see if it can discover the services? Have you tried scanning for `nil` rather than the specific services to see what happens? – Paulw11 Nov 27 '14 at 20:06
  • It works with LightBlue. Scanning for `nil` did not solve the issue. I have tried using some of the most recent sample code provided by Nordic, instead of the old sample code which made use of the blocks above, and now it works :) Thanks – Gina Dec 01 '14 at 15:08

1 Answers1

0

The only thing I can think of is [self.class serviceUUID] does not match the UUID of the service you're looking for. When you initiate the scan, are you filtering by service UUID?

[self.centralManager scanForPeripheralsWithServices:[self.class serviceUUID] options:nil];

If not, that might explain why you're able to discover and connect to it, but not discover that specific service.

Mark
  • 7,167
  • 4
  • 44
  • 68