This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

scanForPeripheralsWithServices issue

I am using:

  • DK52
  • SDK 11
  • Softdevice S132 2.0.0

I have initialized my service as follows:

#define BLE_UUID_BASE_UUID              {0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} 
#define BLE_UUID_BOARD_SERVICE_UUID         0x0202


ble_uuid128_t base_uuid = BLE_UUID_BASE_UUID;
ble_uuid.uuid = BLE_UUID_BOARD_SERVICE_UUID;

err_code = sd_ble_uuid_vs_add(&base_uuid, &ble_uuid.type);
if (err_code != NRF_SUCCESS)
{
    return err_code;
}  

err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
                                    &ble_uuid,
                                    &p_board->service_handle);

nRF Connect shows that the service has the following UUID:

00000202-0000-0000-0000-000000000005

Scanning the device from iOS using:

NSArray *services = @[[CBUUID UUIDWithString:@"00000202-0000-0000-0000-000000000005"]];

[_centralManager scanForPeripheralsWithServices:services options:nil];

The peripheral is not discovered. If I change to:

[_centralManager scanForPeripheralsWithServices:nil options:nil];

the peripheral is discovered and:

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {

    NSLog(@"Discovered service: %@", service.UUID);
}

shows exactly: 00000202-0000-0000-0000-000000000005

I am aware of this:

https://devzone.nordicsemi.com/question/95431/ios-scanforperipheralswithservices-with-uuid-doesnt-work-for-hrm-etc/

I have tried to reverse the uuid but nothing changes.

Since I am using the same iOS code for other devices without any issue, I think something is wrong in my nRF52 setup.

Where am I wrong?

Tks.

Parents
  • one place or the other - not both. If you have a lot of advertising data then you won't have much choice but to put it in the scan data packet because it won't fit in the advertising one. Just look at any of the examples with custom UUIDs, like the Nordic UART sample, that puts a custom service in one or other of them.

    You understand why the scanForPeripherals with nil worked right, because you got the peripheral based on it being a peripheral, THEN connected to it and enumerated the services. That required a connection. scanForPeripherals with a set service ONLY looks at the services advertised in the advertising and scan data, it doesn't connect and read all the services. This is why you don't see it I think.

Reply
  • one place or the other - not both. If you have a lot of advertising data then you won't have much choice but to put it in the scan data packet because it won't fit in the advertising one. Just look at any of the examples with custom UUIDs, like the Nordic UART sample, that puts a custom service in one or other of them.

    You understand why the scanForPeripherals with nil worked right, because you got the peripheral based on it being a peripheral, THEN connected to it and enumerated the services. That required a connection. scanForPeripherals with a set service ONLY looks at the services advertised in the advertising and scan data, it doesn't connect and read all the services. This is why you don't see it I think.

Children
No Data
Related