I am new to iOS development, and study about Bluetooth Low Energy (BLE, Bluetooth 4.0)
for IOS.
I studied the sample code of this link BTLE Central Peripheral Transfer.
And there is another similar sample in this link iOS 7 SDK: Core Bluetooth - Practical Lesson
The applications on the above two links talk about send and receive the text data
between two IOS device base on BLE
.
The App can select to be a central
or Peripheral
, and the central
will receive the text data send from the Peripheral
.
It define the UUID
like the following code in header file
.
#define TRANSFER_CHARACTERISTIC_UUID @"08590F7E-DB05-467E-8757-72F6FAEB13D4"
And after the Central
connect to the Peripheral
, it discover the characteristic from Peripheral
.
If the UUID
is equal to TRANSFER_CHARACTERISTIC_UUID
,then subscribe it by using setNotifyValue:YES
like the following code.
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
// Again, we loop through the array, just in case.
for (CBCharacteristic *characteristic in service.characteristics) {
// And check if it's the right one
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) {
// If it is, subscribe to it
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
}
// Once this is complete, we just need to wait for the data to come in.
}
The question is like the following:
First Question:
I can not find this UUID:@"08590F7E-DB05-467E-8757-72F6FAEB13D4"
in Bluetooth Development Portal.
Is that create by uuidgen
in terminal
?
The second Question:
If I am Central
,and I have subscribe the characteristic
by using setNotifyValue:YES
like the above code.
The BLE will tell the Central
there has new data send from Peripheral
by following code , is the concept correct ?
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
I am new in IOS development and BLE.
Thanks in advance.
These reserved UUIDs cannot be used for any custom services or characteristics, so you need to avoid them. Note: you can actually purchase and reserve a 16-bit alias from the Bluetooth SIG here for a fee of $3,000, which would allow you to use the alias instead. So, to create a UUID for your custom services and characteristics you would:
“A UUID is a universally unique identifier that is guaranteed to be unique across all space and all time” ( Bluetooth 4.2 spec, Vol 3, Part B, section 2.5.1 UUID) A UUID is a 128-bit value. There are reserved UUIDs by the Bluetooth SIG that are generally represented by their 16-bit aliases.
Here is one example of a UUID: acde070d-8c4c-4f0d-9d8a-162843c10333 UUIDs are widely used in part because they are highly likely to be unique globally, meaning that not only is our row’s UUID unique in our database table, it’s probably the only row with that UUID in any system anywhere.
A UUID is a 128-bit value. There are reserved UUIDs by the Bluetooth SIG that are generally represented by their 16-bit aliases. These aliases are used for convenience and represent a 128-bit value computed as follows: These reserved UUIDs cannot be used for any custom services or characteristics, so you need to avoid them.
First question:
uuidgen
in the various WWDC video. The 128-bit UUIDs are not standardized by the Bluetooth SIG and you can use those to run your own profiles.Second question:
setNotifyValue:YES
. From now on, you will receive notifications from the peripheral via [-CBPeripheralDelegate didUpdateValueForCharacteristic:error:]
. The same callback will be invoked when you read a characteristic manually (there's no way to distinguish the read response from a notification in Core Bluetooth).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With