• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Central manager callback didDiscoverPeripheral twice
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Central manager callback didDiscoverPeripheral twice


  • Subject: Re: Central manager callback didDiscoverPeripheral twice
  • From: Michael Kroll <email@hidden>
  • Date: Sat, 21 Jul 2012 10:08:01 +0200

Hello Christian,

I'm calling scanForPeripheralsWithServices like this, since my BLExplr App want's to list every device which is available.

BLELog(@"start scanning...");
[self.cbManager scanForPeripheralsWithServices:nil options:nil];

When I power a BLE Shield for Arduino I built, it results in two entries in my BLExplr UI.

The delegate method didDiscoverPeripheral is called twice. I think this has to do with the advertisement packages. 
The UUID, Name RSSI and Name are the same. In the second entry there is the service included in the ADV package as well.
I think on my side this is not a bug, but what you are describing sounds a little different.

Maybe Joakim can explain this a little bit to clearify this.

Thank you very much,
Michael.


On Jul 21, 2012, at 9:23 AM, Christian Wilhelmsen wrote:

Hi Joakim,

So you think I am using the framework correctly?

Interesting question Michael, hopes that someone has an answer to this

On Jul 21, 2012 9:03 AM, "Michael Kroll" <email@hidden> wrote:
Hello Joakim, Hello Christian,

I encounterd a similar bahvior.
What I eoncountered is, that if my peripheral adviertises a primary service, I can scan for devices and my delegate
is called twice as well. The first entry is a device without the primary service in the advertisement data and the
second ony has the service listed. The entries are completely the same except the additional advertisement
data. It doesn't matter which device I connect, both are workin fine.

Is this how it is implemented in CoreBuetooth?

Kind Regards/Mit freundlichen GrĂ¼ssen,
Dr. Michael Kroll
---
http://www.mkroll.mobi

On 21.07.2012, at 01:29, Joakim Linde <email@hidden> wrote:


Hi Christian, 

Can I ask you to file a bug report at bugreport.apple.com ?

Thanks,
Joakim


On Jul 20, 2012, at 5:04 AM, Christian Wilhelmsen wrote:

I scan for my peripheral like this:
 
    NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
                                                                forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
            // Scan for peripherals with given UUID
            [cm scanForPeripheralsWithServices:[NSArray arrayWithObject:Controller.serviceUUID] options:scanOptions]
 
No problem there, I find the peripheral and are able to connect to it. I also give it the parameter to not scan for more than one peripheral (CBCentralManagerScanOptionAllowDuplicatesKey FALSE), but sometimes the `didDiscoverPeripheral`callback fires twice.
- (void) centralManager:(CBCentralManager *)central
 didDiscoverPeripheral:(CBPeripheral *)peripheral
 advertisementData:(NSDictionary *)advertisementData
 RSSI:(NSNumber *)RSSI
{

    if(!discovered){
        discovered = YES;
        NSLog(@"Discovered");

        [cm stopScan];

        [scanButton setTitle:@"Connect" forState:UIControlStateNormal];
    }
    else if(discovered){
        discovered = YES
        NSLog(@"Already discovered");
    }
}
Some times I get
 
Discovered
Already discovered
as output in my console, and most of the times only the `Discovered` message shows.
In my peripherals delegate I have
 

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

    NSLog(@"Did discover services on peripheral %@", [peripheral name]);

    for (CBService *s in [peripheral services]){

        // DOES NOT ENTER THIS LOOP WHEN didDiscoverPeripheral FIRE TWICE 
        if ([[s UUID] isEqual:Controller.serviceUUID]){
            NSLog(@"Found service on %@", [peripheral name]);
            self.service = s;

            [peripheral discoverCharacteristics:[NSArray arrayWithObject:Controller.throttleCharacteristicUUID] forService:self.service];

        }
    }

        if (self.service == nil){ // THIS HAPPENS WHEN didDiscoverPeripheral FIRE TWICE
        [delegate didDiscoverCharacteristic:NO];
    }
}
 

 

When both occur (didDiscover twice) I am unable to establish the connection, since the for loop is not running as expected (self.service = nil). It works if I reboot the phone again.
I could also wipe out all stored data from previous connections before running my application, and as far as I know, this can only be done by rebooting the phone. Is there any other way, preferably programatically, to do this? I desperately need to figure this out.

 
Thank you very much in advance
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list      (email@hidden)

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list      (email@hidden)

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Central manager callback didDiscoverPeripheral twice (From: Christian Wilhelmsen <email@hidden>)
 >Re: Central manager callback didDiscoverPeripheral twice (From: Joakim Linde <email@hidden>)
 >Re: Central manager callback didDiscoverPeripheral twice (From: Michael Kroll <email@hidden>)
 >Re: Central manager callback didDiscoverPeripheral twice (From: Christian Wilhelmsen <email@hidden>)

  • Prev by Date: PeripheralManager: set the name of the peripheral
  • Next by Date: Re: Central manager callback didDiscoverPeripheral twice
  • Previous by thread: Re: Central manager callback didDiscoverPeripheral twice
  • Next by thread: Re: Central manager callback didDiscoverPeripheral twice
  • Index(es):
    • Date
    • Thread