Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you come up with your own service in BLE?

I have looked at the BLE specification, and found that the Bluetooth SIG has predefined a number of services, like heart rate. I am just wondering if it is possible for me to define a service myself? If can, is there any example available? Thanks.

like image 570
Bob Fang Avatar asked Dec 13 '25 21:12

Bob Fang


1 Answers

yes, it's perfectly possible to define services yourself.

Services and characteristics are all identified by a UUID. For example the BLE Services page lists all standardized services and the assigned UUIDs.

As you can see the Heart Rate services uses 0x180D, which is a 16-bit short form reserved for standardized services only. The only requirement when defining your own service is that you use a 128-bit long form UUID.

Use uuidgen (available on Mac OS X) to generate a random (unique) UUID yourself:

uuidgen
# example result: 94B01578-5603-4D5A-8DFF-9365A1C4AC93

You can use this to publish and identify your own service. This can either be done on your own custom hardware, or through software on iOS (since you mention core-bluetooth).

Create your CBMutableService:

CBUUID *serviceUUID = [CBUUID UUIDWithString:@"94B01578-5603-4D5A-8DFF-9365A1C4AC93"];
CBMutableService *myService = [[CBMutableService alloc] initWithType:serviceUUID primary:YES];
// add some characteristics, also identified by your own custom UUIDs.

Finally see addService: & startAdvertising: on CBPeripheralManager to start publishing your custom service.

After publishing this service using an iOS device you can scan for and connect to that service using another iOS device or a Mac, using the CBCentralManager class.

like image 141
Joris Kluivers Avatar answered Dec 15 '25 12:12

Joris Kluivers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!