Reputation: 491
I have an app that connects to a CC2541 over Bluetooth Low Energy. I simply want to cache something unique to each device so a user only connects to "their" device. I've tried using
- (NSArray *)retrievePeripheralsWithIdentifiers:(NSArray *)identifiers
and even scanning and comparing the UUID's of the scanned peripherals, but I have to select a newly generated UUID every few app launches. The same code worked well on 8.1 and I rarely (if ever) had to select a new UUID.
I've debated checking the System ID (2A23 uuid) in the Device Information service, but that requires a connection to check the address so I'd have to connect to each nearby peripheral, get and compare the System ID, then either stay connected or disconnect and check the next one.
The CC2541 code I'm running isn't using pairing and I'd like to keep it that way. I'm curious if anyone else has found a solution to this situation.
Upvotes: 2
Views: 2247
Reputation: 491
I just want to post some code here that may help others in the future.
Put this somewhere outside of a function:
__xdata __no_init uint8 BT_MAC_ADDR[6] @ 0x780E;
Put this in your advertData array:
7, //length of data
GAP_ADTYPE_MANUFACTURER_SPECIFIC, //Custom data
0,0,0,0,0,0, //Placeholder bytes
And finally update the advertData before you call GAPRole_SetParameter.
uint8 advertSize = sizeof(advertData);
memcpy(&advertData[advertSize-6], BT_MAC_ADDR, 6);
Upvotes: 0
Reputation: 2211
Having been down this road, spending weeks to find a work-around to the limitations, the only way I have found is if you have control over the hardware and can put your own unique identifier in the advertising packet. While one can make all kinds of assertions about the (in)sanity of this, it is what it is.
Upvotes: 2