drn
drn

Reputation: 439

Device found by LightBlue but not iOS CoreBluetooth

I'm using a BLE Shield on an Arduino - LightBlue detects correctly the BLE shield. Now, I'm trying to make an app that scans for all the BLE devices and connect to the right one so I can send some information to my shield from my app.

But the app doesn't detect the BLE Shield (it detects another BLE device though...).

My code is the following:

- (void)centralManagerDidUpdateState:(CBCentralManager *)central{

    switch (central.state) {
        case CBCentralManagerStatePoweredOn:
            msg=[NSString stringWithFormat:@"Bluetooth is currently powered on and available to use."];
            [cbcManager scanForPeripheralsWithServices:[NSArray arrayWithObject:[CBUUID UUIDWithString:@"180A"]] options:nil];
            break;
    }
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:   (CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSLog(@"%@\n--------------------", advertisementData.description);
}

I checked with LightBlue, 180A is the right service UUID for my shield. I also tried to scan by passing a nil value instead of the service UUID but it still can't be detected.

The code seems to work as one of my BLE device is found...Any ideas why my shield can be detected by LightBlue and not this piece of code?

Upvotes: 2

Views: 525

Answers (1)

Andrew
Andrew

Reputation: 15377

You could try passing the allow duplicates option when scanning, since it's possible its discovery is being suppressed if it thinks it's a duplicate.

NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];    

[cbcManager scanForPeripheralsWithServices:nil options:options];

Upvotes: 2

Related Questions