Re: Connecting to a CC2540 from the Xcode simulator
Re: Connecting to a CC2540 from the Xcode simulator
- Subject: Re: Connecting to a CC2540 from the Xcode simulator
- From: Rick Mann <email@hidden>
- Date: Sat, 04 May 2013 13:48:08 -0700
Be sure to stop scanning before you attempt to connect. I found that although it worked on iPad 3, it did not work in the simulator unless I stopped scanning first.
Actually, it did connect, but took a very, very long time.
On May 4, 2013, at 13:41 , Peter Watkins <email@hidden> wrote:
> I've now tested the my code and device on actual hardware and on the simulator. Here are my results:
>
> iOS 6 Simulator: Doesn't connect
> iOS5 Simulator: Connects
> iOS5 Device: Connects
> iOS6 Device: Connects
>
> So the problem seems to be isolated to the iOS 6 simulator. Odd.
>
> -Peter
>
>
> On May 1, 2013, at 6:51 PM, Rick Mann <email@hidden> wrote:
>
>> I've had some oddness, but it's currently working for me.
>>
>> For yucks, try Reset Content and Settings on the simulator. Maybe BT cached something (it caches aggressively).
>>
>> --
>> Rick
>>
>> On Apr 28, 2013, at 15:28 , Peter Watkins <email@hidden> wrote:
>>
>>> I'm developing a Bluetooth Low Energy peripheral for iPhone / iPad. To start with, I'm using TI's CC2540 Development Kit: http://www.ti.com/tool/cc2540dk
>>>
>>> I've followed TN2295 for setting up my Mid 2012 MacBook Air along with a Cirago BTA8000 Bluetooth 4.0 dongle. I've made a sample iOS application that I can run in the simulator. When my application runs, I can scan and see the CC2540 dev kit, but I can't connect to it. In fact, looking at a packet dump, it appears that Core Bluetooth never even attempts to connect:
>>> http://picpaste.com/packet_dump-RObRnY97.gif
>>> (click on the image to get a higher-resolution version).
>>>
>>>
>>> I haven't tried an actual device yet (since we haven't gotten one yet). But time is running out, and I'd like to get this working in the simulator. Has anyone else run into problems connecting to devices (in or out of the simulator)? Any suggestions? I've posted my code below. Even a simple example is a bit long.
>>>
>>> Thanks,
>>>
>>> Peter
>>>
>>>
>>>
>>> =========================== MseiAppDelegate.h ===========================
>>>
>>> #import <UIKit/UIKit.h>
>>> #import <CoreBluetooth/CoreBluetooth.h>
>>> #import <CoreBluetooth/CBService.h>
>>>
>>> @interface MseiAppDelegate : UIResponder <UIApplicationDelegate, CBCentralManagerDelegate>
>>>
>>> @property (strong, nonatomic) UIWindow *window;
>>>
>>> @property (strong, nonatomic) CBCentralManager *centralManager;
>>> @property (strong, nonatomic) CBPeripheral *thePeripheral;
>>> @property (assign, nonatomic) int didDiscoverPeripheralCalls;
>>>
>>> @end
>>>
>>> =========================== MseiAppDelegate.m ===========================
>>> #import "MseiAppDelegate.h"
>>>
>>>
>>> @implementation MseiAppDelegate
>>>
>>> @synthesize didDiscoverPeripheralCalls;
>>>
>>> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
>>> {
>>> self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
>>> // Override point for customization after application launch.
>>> self.window.backgroundColor = [UIColor whiteColor];
>>> [self.window makeKeyAndVisible];
>>>
>>> self.didDiscoverPeripheralCalls = 0;
>>> self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
>>>
>>> return YES;
>>> }
>>>
>>> - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
>>> printf("didDiscoverPeripheral() call number %d\r\n", didDiscoverPeripheralCalls++);
>>>
>>> NSEnumerator *enumerator = [advertisementData keyEnumerator];
>>> id key;
>>> while ((key = [enumerator nextObject])){
>>> NSLog(@"%@ %@", key, [advertisementData objectForKey: key]);
>>>
>>> }
>>>
>>> if (didDiscoverPeripheralCalls < 2) {
>>> return;
>>> }
>>>
>>> _thePeripheral = peripheral;
>>> [central stopScan];
>>>
>>> NSLog(@"Attemping to connect...");
>>> [central connectPeripheral:_thePeripheral options:nil];
>>> }
>>>
>>> - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
>>> NSLog(@"Connected to a peripheral");
>>> }
>>>
>>> - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
>>> NSLog(@"Failed to connect to a peripheral: %@", error);
>>> }
>>>
>>> /*!
>>> * @method centralManagerStateToString:
>>> *
>>> * @param state State to print info of
>>> *
>>> * @discussion centralManagerStateToString prints information text about a given CBCentralManager state
>>> *
>>> */
>>> - (const char *) centralManagerStateToString: (int)state{
>>> switch(state) {
>>> case CBCentralManagerStateUnknown:
>>> return "State unknown (CBCentralManagerStateUnknown)";
>>> case CBCentralManagerStateResetting:
>>> return "State resetting (CBCentralManagerStateUnknown)";
>>> case CBCentralManagerStateUnsupported:
>>> return "State BLE unsupported (CBCentralManagerStateResetting)";
>>> case CBCentralManagerStateUnauthorized:
>>> return "State unauthorized (CBCentralManagerStateUnauthorized)";
>>> case CBCentralManagerStatePoweredOff:
>>> return "State BLE powered off (CBCentralManagerStatePoweredOff)";
>>> case CBCentralManagerStatePoweredOn:
>>> return "State powered up and ready (CBCentralManagerStatePoweredOn)";
>>> default:
>>> return "State unknown";
>>> }
>>> return "Unknown state";
>>> }
>>>
>>> - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
>>> printf("Status of CoreBluetooth central manager changed %d (%s)\r\n",central.state,[self centralManagerStateToString:central.state]);
>>> if (central.state == CBCentralManagerStatePoweredOn) {
>>> NSLog(@"Started scanning for any peripherals");
>>> [self.centralManager scanForPeripheralsWithServices:nil options:0]; // Start scanning
>>> }
>>> }
>>>
>>> _______________________________________________
>>> 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
>>
>>
>> --
>> Rick
>>
>>
>>
>
--
Rick
_______________________________________________
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