Bluetooth name caching

Our peripheral firmware is in development so we've been changing the device address and device name (which we're using for the ID) often. We've noticed that the name reported by iOS can be out of date, since it's caching it against the device address? I've tried switching Bluetooth off and on, even switching the phone off and on, but to no avail.


Also, the 'name' is not matching up to 'kCBAdvDataLocalName' in the advertising data.


For example, our peripheral is currently set to (and we've verified this with CySmart on the laptop):


Address: ...:00:00:27

Shortened Local Name: 000027 (This is set in the Scan Response Data)


But iOS is reporting the device data as follows. 'kCBAdvDataLocalName' is up to date, but 'name' isn't...



{

advertising = {

kCBAdvDataIsConnectable = 1;

kCBAdvDataLocalName = 000027;

};

id = "379E9807-8F94-6397-CECE-E63F027FA614";

name = 000025;

rssi = "-65";

}


So, two questions please:


  • Anyone know why 'name' doesn't match up to 'kCBAdvDataLocalName'?
  • Is there a way to (preferably non-programmatically) clear the cache?


Thanks in advance!

Answered by Engineer in 61155022

There are 2 names to consider. The advertising name and the GAP (Generic Access Profile) name.

For a peripheral which iOS has never connected before, the 'name' property reported is the advertising name. Once it is connected, the GAP name is cached, and is reported as the peripheral's name. GAP name is considered a "better" name due to the size restrictions on the advertising name.


There is no rule that says both names must match. That depends on your use case and implementation. Some people will consider the GAP name as the fixed name, but the advertising name more of an "alias", as it can easily be changed.


If you want both names in sync, you should change the GAP name as well along with the advertised name. Implemented properly, your CB manager delegate will receive a call to - peripheralDidUpdateName:


If you want to manually clear the cache, you need to reset the iOS device.

Accepted Answer

There are 2 names to consider. The advertising name and the GAP (Generic Access Profile) name.

For a peripheral which iOS has never connected before, the 'name' property reported is the advertising name. Once it is connected, the GAP name is cached, and is reported as the peripheral's name. GAP name is considered a "better" name due to the size restrictions on the advertising name.


There is no rule that says both names must match. That depends on your use case and implementation. Some people will consider the GAP name as the fixed name, but the advertising name more of an "alias", as it can easily be changed.


If you want both names in sync, you should change the GAP name as well along with the advertised name. Implemented properly, your CB manager delegate will receive a call to - peripheralDidUpdateName:


If you want to manually clear the cache, you need to reset the iOS device.

Thanks Gualtier, that's really helpful!


Please may I just ask a quick follow-up question? You mentioned the advertising name can be easily changed... Do you know if it also gets cached, and if so, how to manually clear that too?

Advertising name does not get cached. It is not a property that would be cached, as it arrives live with the advertising from the peripheral.

For testing your bluetooth firmware, if you are not constructing a resolvable random address, I recommend changing the BD_ADDR for every new image you are testing. Then nothing should be cached. There is one recommendation by the BLE standard on the two naming conventions. The advertised name can be shorter than the GAP device_name but they should both be the same name. So if the full name of the device is 'PedoMeter' then a well-formed short name would be 'Pedo' not 'PM'.

I would just like to add that the advertisement name (as well as other scan response data) is not live with every advertisement packet during an ongoing scan. You can clearly see that the data is only updated about every 30-60 seconds. We have tested this by setting up a custom hardware and changing the scan response data on the fly while advertising.

Was this with the scanning app in the foreground or in the background and/or the screen off?

Gualtier, thanks for the info. I'm working on a project where I have control of both the app and the BLE device firmware.


peripheralDidUpdateName looks like exactly what I need -- but when I implement it, it isn't getting called. The BLE device's name is definitely getting changed but my iPhone returns the old name under peripheral.name and never fires peripheralDidUpdateName ... what might I be missing?

Are you changing the GAP name on the device?

I've been attempting to respond but keep getting "message contains invalid characters" ... ***.

NSString *name = peripheral.name;
NSString *identityName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
Bluetooth name caching
 
 
Q