Core Bluetooth

teas
er
Core Bluetooth
CocoaHeads Sthlm 2014
Edward Patel
Me
• I work at
• Love programming
• Love gadgets
• Love programming gadgets
Bluetooth Low Energy
WWDC’13 Keynote
• Anki DRIVE
Bluetooth Low Energy
• Invented by researchers at Nokia
• For small things
• Run a long time on a coin-cell battery
• Look for “Internet-of-Things”
iOS
• Introduced in iOS 5
• Extended in iOS 6 (can become a “Peripheral”)
• Cleaning API in iOS 7 + better caching and
handling including backgrounding.
Framework
Core Bluetooth Framework Reference
The Core Bluetooth framework provides the classes needed for your iOS and Mac apps to
communicate with devices that are equipped with Bluetooth low energy wireless technology.
Class References
CBATTRequest
CBCentral
CBCentralManager
CBCharacteristic
CBDescriptor
CBMutableCharacteristic
CBMutableDescriptor
CBMutableService
CBPeripheral
CBPeripheralManager
CBService
CBUUID
Protocol References
CBCentralManagerDelegate
CBPeripheralDelegate
CBPeripheralManagerDelegate
Other References
Core Bluetooth Constants
There are only two hard things
in Computer Science:
cache invalidation
naming things
off-by-one errors
Naming things...
Central
Peripheral
advertise
wants data
has data
(client)
(server)
Peripheral
Service
Characteristic
Characteristic
Service
Characteristic
Characteristic
Characteristic
• Can be read, and writable
• Can be integers, strings etc
• Can be “Notifiable”
GATT Generic Attribute Profile
• A kind of contract known in advance
• Defines a number of UUID’s for Services
and Characteristics
and value types.
• There are standardized ones,
i.e Heart rate monitors
•
You can define your own
Service
Characteristic
Characteristic
Service
Characteristic
Characteristic
Find the standardized?
https://developer.bluetooth.org/gatt/
UUID’s
• Standardized by Bluetooth SIG are short, 16 bit
• Free are long, 128 bits
Heart rate monitor service
“180D”
Your own message service
“0CDA25F083E54CBCB7C97FB2AC3DC476”
Workflow of a Central in iOS
Create a CBCentralManager
Discover Peripherals with Services
Connect to Peripheral
Discover Services for Peripheral
Discover Characteristics for Service
Where to start?
Download some apps from App Store
Do it now!
• LightBlue - Bluetooth Low Energy
• TI BLE Multitool
Get some hardware?
• SensorTag (6 sensors)
• Arduino Shields, i.e.Tinyduino or BLE Shield
• BLE Mini by RedBearLabs
• BLE-112 Evaluation board
• Gimbal iBeacon
• Or just use two iPhones
Get some sample code?
• HiBeacons by Nick Toumpelis (a Spotifier)
• Temperature Sensor by Apple
• Also, checkout WWDC videos
Thanks!