0
votes

I am trying to discover services after connecting to the desired peripheral, but I only can only find non-existant services according to UUIDs. What I mean by that is; that as a means of checking, I am also using an app store app called "Light Blue". Light Blue is just a BLE explorer which identifies all peripherals, services and characteristics. I can see the desired services and characteristics using Light Blue, so I know they exist and the ones which Light Blue identifies are correct.

Here is my code and how I identify all of the services, included services, and characteristics:

- (void)printAllChar:(CBPeripheral*)p {
    printf("**************************************\n");
    printf("Listing all services and characteristics\n");

    CBService * s, * inc;
    CBCharacteristic * c;

    //Discover all services on peripheral
    [p discoverServices:nil];

    printf("%d services discovered\n", p.services.count);
    for(int i = 0; i < p.services.count; i++){

        //Traverse all services
        s = [p.services objectAtIndex:i];
        printf("Service %d: %s\n", i+1, s.UUID);

        [p discoverIncludedServices:nil forService:s];

        printf("    Included Services Discovered: %d\n", s.includedServices.count);

        //Traverse all included services of each service
        for(int k = 0; k < s.includedServices.count; k++){
            inc = [s.includedServices objectAtIndex:k];
            printf("    %d: %s\n", k+1, inc.UUID]);            
        }

        [p discoverCharacteristics:nil forService:s];

        printf("%d Characteristics discovered\n", s.characteristics.count);

        //Traverse all characteristic of each service
        for(int j = 0; j < s.characteristics.count; j++){
            c = [s.characteristics objectAtIndex:j];
            printf("Characteristic %d: %s\n", j+1, c.UUID);
        }
    }
}

^^^I know the print functions wont actually run since s.UUID is not a string variable, I have removed all the conversion code to make it more readable.

I think it is worth mentioning that the callback function didDiscoverServices never gets called.

Here is a sample output of the above code:

**************************************
Listing all services and characteristics
3 services discovered
Service 1: 02000000-0200-0000-60D0-E03B02000000
    Included Services Discovered: 0
    0 Characteristics discovered
Service 2: 02000000-0200-0000-18C0-F03B00005444
    Included Services Discovered: 0
    0 Characteristics discovered
Service 3: 00000000-1000-0000-B4CC-E03B82130001
    Included Services Discovered: 0
    0 Characteristics discovered

None of the services are ones that I would expect. I have connected the correct peripheral, but these services are completely unknown to me.

The service ids that I should find are as follows:

//Service UUID
#define BLE_DEVICE_SERVICE_UUID             "713D0000-503E-4C75-BA94-3148F18D941E"

//Characteristic UUID  
#define BLE_DEVICE_VENDOR_NAME_UUID         "713D0001-503E-4C75-BA94-3148F18D941E"

#define BLE_DEVICE_RX_UUID                  "713D0002-503E-4C75-BA94-3148F18D941E"

#define BLE_DEVICE_TX_UUID                  "713D0003-503E-4C75-BA94-3148F18D941E"

#define BLE_DEVICE_RESET_RX_UUID            "713D0004-503E-4C75-BA94-3148F18D941E"

#define BLE_DEVICE_LIB_VERSION_UUID         "713D0005-503E-4C75-BA94-3148F18D941E"

Does anyone have any idea what is going on?

If it is relevant, I am using a RedBearLabs BLEMini.

1
What's the service UUID you should find? Why don't you use Objective-C more rather than C, with NSLog for example? - Larme
I edited my post with more information. I am just more used to C I suppose, this is my first experience with IOS development. Would there be anymore useful information using NSLog? - mgeno
Well, NSLog simplify a lot of things, I think, like adding a TimeStamp to your logs, "adding automatically a \n" at the end and the magical %@ (Example NSLog(@"Service %d: %@", i+1, s.UUID);. Then, do you use the callBack methods? Did you see the Temperature Sensor Sample from Apple? - Larme
Yes I have, I really appreciate your help. I think the structure of all my calls mimics most of the examples I have seen, although that cannot be entirely true since I have having errors - mgeno
Did you tries with the Temperature Sensor sample from Apple, modifying the scan? - Larme

1 Answers

0
votes

You really should try doing this in the callback method. You said they don't get called -- have you set your class as a CBPeripheralDelegate and also set the Peripheral's delegate to self?

(Also, as an aside: Objective-C has a foreach loop that is more convenient than manually setting up a for loop with a counter):

for(CBService *s in peripheral.services){
    NSLog(@"%@",s.uuid); //print the service uuid to console
}