Reputation: 2199
I am looking to create a cross-platform application that allows me to periodically advertise the devices Mac address(though I have realized for some reason I receive 3 for a single device.) so that it can be recorded and used to reference short manual user advertisement such that each advertisement can be identified by a specific user; however, It seems as though I have fallen into issues regarding UUIDs on BLE
After searching for a while I still seem to be a bit confused regarding UUID's in the BLE service. Originally I decided to use a custom BLE which repeatedly failed to advertise either with an odd error or due to the packet being to large even though the data was only 1 byte long. I realized that the UUIDs must be in the form xxxxxxxx-0000-1000-8000-00805F9B34FB
. Anything outside of this will send the full UUID which is too large when advertising without being connected. I have also found that I can use any UUID prefix in the upper half (0000XXXX
) that is not in the reserved range 0x000E
– 0x01FF
.
Is this a correct assumption and I can use any UUID that does not conflict with the criteria i.e 00000200 - 0000FFFF. I ask because I seem to fall into issues when choosing a UUID in that range and as I understand creating custom UUID's outside the range is a bad idea on BLE since it would be forced to use 16 of the 20-23 bytes available. Any input regarding this?
Also Is their a predefined way to send advertisement's of the user device so that it can be cached and used to identify other user advertisements?
EDIT:
There arrives a need in the project to connect phones cross-platform along with other equipment in an connectionless manner. Initially I planned for a device to repeatedly advertise it’s identity along with a name and unique MAC address that can be used to identify user messages uniquely. Any device without the cached user identity would simply drop incoming packet’s from that user. – kdgwill 9 mins ago
I actually think it would be easier if I could somehow connect to 5-10 devices at a time; however, the idea is not to bother users w/ repeated prompts when new devices are added. As such I figured using advertising and flooding would help but msg sizes vary. Is it possible bother the user once for a connection prompt and autoconnect each additional BLE device. If I could somehow connect multiple devices on a 1 to 1 basis without having to prompt the user each time while still scanning for other possible connections to be made that would be very useful but I do not think BLE allows for that. – kdgwill 8 secs ago edit
Using the identifierForVendor or CBAdvertisementDataServiceUUIDsKey is a great way to uniquely identify each user; however, that would mean that if I don't use 1 of the registered UUIDs which I can probably just randomly choose one for the time being. that the overhead would be either 4-16 + however many bytes it takes to identify each packet.
Upvotes: 2
Views: 3329
Reputation: 53870
You can only use the shorter 4 byte UUIDs if you register the device with the Bluetooth consortium, otherwise, you must use the longer 16 byte UUIDs.
You are correct that you get to pick the 16 byte UUIDs for the services (and characteristics). You should pick the IDs quasi-randomly, and always use the same UUID for that particular type of service/characteristic.
Because each packet that you send must include the destination service UUID, using a longer UUID uses up a lot of the bytes available in the payload. Less bytes available per packet means more packets must be sent for larger messages, increasing the time it takes to send a message. If you are not sending messages, but simply using advertisement data, then this isn't of concern, though you'll have less bytes available for advertisement data.
The MAC address is not available in code using the iOS Bluetooth framework. iOS 8+ can send a random MAC address, so you should not count on identifying a device by that anyway.
Since the MAC address is not available to you, you may wish to connect and send a unique id (such as identifierForVendor
) via the BLE connection, or possibly include a small ID in the advertisement data via CBAdvertisementDataLocalNameKey
.
Upvotes: 2