• 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: Using CoreBluetooth from Command Line Tool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using CoreBluetooth from Command Line Tool


  • Subject: Re: Using CoreBluetooth from Command Line Tool
  • From: email@hidden
  • Date: Thu, 04 Apr 2013 17:16:03 -0700

If you use the retrieve and connect do you get the connect callback delegate?  Everything works for me until the connect - I never get the didConnectPeripheral delegate call.

I just recompiled with ARC enabled and also created a static reference for a WirelessBandManager *.  It still doesn't work for me.  I'm linking with IOBluetooth.framework and Foundation.framework - is there any others you are adding?

BTW, I come from an embedded background so I'm more used to managing the retain/release cycle myself - ARC is a whole new concept in my old-school vocabulary...

-- dave

On Apr 4, 2013, at 4:33 PM, Andras Kovi <email@hidden> wrote:

> I tried your code. Turned it to ARC and kept a reference to the WirelessBandManager in the main function. It works well for me. I tried it with the queue and the main queue too and with scan and retrieve.
>
> Don't you have to retain the WirelessBandManager instance in the main function? Just asking. I generally use ARC and shiver from these retain-release calls.
>
> Andras
>
>
> On 2013.04.05., at 0:22, email@hidden wrote:
>
>> It is a proprietary device I'm connecting with, so the UUID isn't changing (it is the same UUID I see when I scan from my GUI app or command line app).
>>
>> The symptoms feel like a dead lock on the queue CoreBluetooth is using to send events.  Being I have no visibility it is hard to know for sure.
>>
>> Below is a stripped version of the code that fails to respond to the connect.  Note: the UUID is hardcoded to simplify my testing.  Using the same hardcoded UUID in my GUI version works and behaves as expected.
>>
>> The debug log output is the following (nothing more)
>>
>> 2013-04-04 15:18:15.836 cbtest[4025:1303] Did update state to: 5
>> 2013-04-04 15:18:15.838 cbtest[4025:1303] Did retrieve peripheral: <CBConcretePeripheral: 0x10010bf40>
>>
>> -- dave
>>
>> #import <Foundation/Foundation.h>
>> #import <IOBluetooth/IOBluetooth.h>
>>
>> @interface WirelessBandManager : NSObject <CBCentralManagerDelegate>
>> {
>>   CBCentralManager *      mBLEManager;
>>   CBPeripheral *          mPeripheral;
>>   dispatch_queue_t        mBleDispatchQueue;
>> }
>> @end
>>
>> @implementation WirelessBandManager
>>
>> - (id)init
>> {
>>   self = [super init];
>>   if (self)
>>   {
>>       mBleDispatchQueue = dispatch_queue_create("com.xyz.ble.mgr", DISPATCH_QUEUE_SERIAL);
>>       mBLEManager = [[CBCentralManager alloc] initWithDelegate:self queue:mBleDispatchQueue];
>>   }
>>   return self;
>> }
>>
>> #pragma mark -
>> #pragma mark CBCentralManager Delegate Methods
>> - (void)centralManagerDidUpdateState:(CBCentralManager *)central
>> {
>>   NSLog(@"Did update state to: %d",(int)central.state);
>>   if (central.state == CBCentralManagerStatePoweredOn)
>>   {
>>       NSMutableArray * uuids = [[NSMutableArray alloc] initWithCapacity:1];
>>       NSString * uuidStr = @"42EF45DA-718D-42C2-AB91-A6588121E52A";
>>       CFUUIDRef uuidRef = CFUUIDCreateFromString(NULL, (CFStringRef)uuidStr);
>>       [uuids addObject:(id)uuidRef];
>>       CFRelease(uuidRef);
>>
>>       [mBLEManager retrievePeripherals:uuids];
>>       [uuids release];
>>   }
>> }
>>
>> - (void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals
>> {
>>   mPeripheral = [peripherals[0] retain];
>>
>>   NSLog(@"Did retrieve peripheral: %@",mPeripheral);
>>
>>   NSDictionary *connOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBConnectPeripheralOptionNotifyOnDisconnectionKey];
>>
>>   [mBLEManager connectPeripheral:mPeripheral options:connOptions];
>> }
>>
>> - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
>> {
>>   NSLog(@"Did connect to peripheral: %@",peripheral);
>> }
>> - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
>> {
>>   NSLog(@"Did FAIL to connect to peripheral: %@ Error:%@",peripheral,error);
>> }
>> - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
>> {
>>   NSLog(@"Did disconnect from peripheral: %@ Error:%@",peripheral,error);
>> }
>>
>>
>> @end
>>
>> #pragma mark -
>> #pragma mark MAIN
>> // =========================================================================
>> // main()
>> // =========================================================================
>> int main(int argc, const char * argv[])
>> {
>>   @autoreleasepool
>>   {
>>       [[WirelessBandManager alloc] init];
>>       dispatch_main();
>>   }
>>   return 0;
>> }
>>
>>
>> On Apr 4, 2013, at 2:34 PM, Andras Kovi <email@hidden> wrote:
>>
>>> Hi Dave,
>>>
>>> I haven't tried to run CB in a command line app, but one little note: make sure you don't use WiFi while connected. WiFi and BLE interfere severely on my Mac Mini. I guess it's similar on the MacBook.
>>>
>>> Do you want to connect to an i* device or a proprietary one? i* devices change their BLE addresses every few minutes. If you don't use secure connection, then I think they can get out of sync. This is probably the reason why you need to do a scan. Command line or Cocoa should not make any difference IMHO.
>>>
>>> Andras
>>>
>>> On 2013.04.04., at 22:40, email@hidden wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm trying to write a simple command line app that uses CoreBluetooth on an BLE capable mac book (OSX v10.8.3).
>>>>
>>>> If I use the retrievePeripherals I get the delegate didRetrievePeripherals to fire.  If I then try to connect to the found peripheral, the didConnectPeripheral delegate never fires.
>>>>
>>>> However, if I scan for peripherals and get the delegate didDiscoverPeripheral to fire.  I can then connect and connect succeeds.  However, once I'm connected and have my characteristics, the data I receive from my peripheral is not reliably received.
>>>>
>>>> Using similar code in a GUI application works perfect.
>>>>
>>>> Has anyone else been successful running the CoreBluetooth stack from within a command line app?
>>>>
>>>> In my main I essentially create a dispatch_queue and let it run my operations via dispatch_async.  Meanwhile, I let main just call dispatch_main().
>>>>
>>>> -- dave
>>>> _______________________________________________
>>>> 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
>>


 _______________________________________________
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

  • Follow-Ups:
    • Re: Using CoreBluetooth from Command Line Tool
      • From: Andras Kovi <email@hidden>
References: 
 >Using CoreBluetooth from Command Line Tool (From: email@hidden)
 >Re: Using CoreBluetooth from Command Line Tool (From: Andras Kovi <email@hidden>)
 >Re: Using CoreBluetooth from Command Line Tool (From: email@hidden)
 >Re: Using CoreBluetooth from Command Line Tool (From: Andras Kovi <email@hidden>)

  • Prev by Date: Re: Using CoreBluetooth from Command Line Tool
  • Next by Date: Re: Using CoreBluetooth from Command Line Tool
  • Previous by thread: Re: Using CoreBluetooth from Command Line Tool
  • Next by thread: Re: Using CoreBluetooth from Command Line Tool
  • Index(es):
    • Date
    • Thread