Maria
Maria

Reputation: 334

iOS does not detect new peripheral name

We are using CC2540 BLE Chip as peripheral and an iOS 7.0.4 iPhone is playing central role.

We change the peripheral name, but this change is only shown when we disconnect from iOS device and reconnect.

It works fine in Android using this code to change peripheral name in response data:

GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( deviceName ), deviceName );

We are using this code to change the peripheral name of GAP layer in iOS:

GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );

Is there any way to change peripheral name so that no reconnection is needed?

Upvotes: 1

Views: 2463

Answers (2)

saitjr
saitjr

Reputation: 159

you can get the local name from advertisementData. There is the solution: Incorrect BLE Peripheral Name with iOS

And on Apple Developer Forums, here is the detail of CBPeripheral name property.

Upvotes: 1

Gabriel.Massana
Gabriel.Massana

Reputation: 8225

For me the problem is in the iOS App code.

The basic order of calls to connect in iOS to BLE is:

centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil
                                                    options: nil];

this last one invokes:

- (void) centralManagerDidUpdateState:(CBCentralManager *)central

then if central.state is CBCentralManagerStatePoweredOn you can:

[centralManager scanForPeripheralsWithServices:nil 
                                       options:nil];

this last one invokes:

- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

Apple here recommends: "You must retain a local copy of the peripheral if any command is to be performed on it."

That means you should create a property for your CBPeripheral like:

self.myPeripheral = peripheral;

It is here where you have a peripheral.name or self.myPeripheral.name

If you don't call again in your code: [centralManager scanForPeripheralsWithServices:nil options:nil]; what you have is the information retrieved the first time. You should make the call again if you want to refresh the name. Maybe with a timer.

Hope that helps.

EDIT

Check: Core Bluetooth Programming Guide: Performing Common Central Role Tasks

Upvotes: 1

Related Questions