Your SlideShare is downloading. ×
BTLE (Bluetooth Low Energy) and CoreBluetooth
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

BTLE (Bluetooth Low Energy) and CoreBluetooth

10,079
views

Published on

This presentation is on Bluetooth low energy and how Apple's Core Bluetooth framework works to expose the higher level application layer to iOS and Mac developers.

This presentation is on Bluetooth low energy and how Apple's Core Bluetooth framework works to expose the higher level application layer to iOS and Mac developers.

Published in: Technology, Health & Medicine

0 Comments
22 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
10,079
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
392
Comments
0
Likes
22
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Bluetooth LE, CoreBluetooth @zachdennis @zdennis ! mutuallyhuman.com
  • 2. Bluetooth LE
  • 3. What is BTLE?
  • 4. A short range, ultra-low power consuming wireless technology.
  • 5. Shares the “Bluetooth” name, but has different design goals in mind.
  • 6. Power Consumption Years, not hours or days.
  • 7. Short range ~ 50m
  • 8. Packet-based Short bursts of data.
  • 9. Intervals Ad Ad Data Ad Data
  • 10. Multiple channels #1 Ad Ad Data Ad Data #2 Ad Ad Data Ad Data #3 Ad Ad Data Ad Data
  • 11. Device A is looking. Scan Scan Data Ad Ad Data Ad Data Ad Ad Data Ad Data Device B is advertising.
  • 12. Frequency hopping
  • 13. Connection-less Devices do not need to maintain connections.
  • 14. Pairing e.g. iOS - happens when Insufficient Authentication error code is sent from the peripheral.
  • 15. Security Devices pair, keys are distributed, and the connection is encrypted. ! Encryption is AES-128.
  • 16. Why BTLE?
  • 17. *Borrowed from 2012 WWDC CoreBluetooth Talk
  • 18. 1 billion+ devices
  • 19. *Borrowed from 2013 Apple WWDC talk
  • 20. How BTLE Works
  • 21. The Stack
  • 22. Key Terms • Central • Peripheral • Service • Characteristic • Descriptor
  • 23. Central (wants data) Peripheral (has data)
  • 24. Central Peripheral advertising
  • 25. Central Peripheral advertising scan
  • 26. Central Peripheral advertising scan advertising
  • 27. Central Peripheral advertising scan advertising discover services Heart Monitor
  • 28. Central Peripheral advertising scan advertising discover services Heart Monitor discover characteristics BPM
  • 29. Central Peripheral advertising scan advertising discover services Heart Monitor discover characteristics BPM read value 95
  • 30. Central Peripheral advertising scan advertising discover services Heart Monitor discover characteristics BPM read value 95 observe value BPM 95
  • 31. Central Peripheral advertising scan advertising discover services Heart Monitor discover characteristics BPM read value 95 value changed BPM 95 BPM observe value 95 BPM 98
  • 32. Service A service is a human-readable specification of a set of characteristics and their associated behavior.
  • 33. Two kinds of services There are primary services and secondary services.
  • 34. Nested services Services can contain other services.
  • 35. Characteristic A characteristic is a bit of data that has a known format labeled with a UUID. They are intended for computer-readable format as opposed to human-readable text.
  • 36. Profiles A profile is a specification that describe two or more devices, with one or more services on each device, how they discover each other, connect, and otherwise interact. Profiles define roles for devices to play.
  • 37. Heart Rate Profile Collector Heart Rate Sensor Heart Rate Service Device Information Service
  • 38. Heart Rate Profile GATT CLIENT GATT SERVER Collector Heart Rate Sensor Heart Rate Service Device Information Service
  • 39. Profiles & Services Profiles contain services. Services can be contained by multiple profiles.
  • 40. Anatomy of a Peripheral Peripheral Service Characteristic Descriptor Characteristic Service Characteristic
  • 41. Apple’s Approach to BTLE
  • 42. Simple Powerful
  • 43. Technology Stack
  • 44. *Borrowed from 2012 WWDC CoreBluetooth Talk
  • 45. Supported Profiles • Generic Attribute Profile Service • Generic Access Profile Service • Bluetooth Low Energy HID Service • Battery Service • Time Service • Apple Notification Center Service
  • 46. CoreBluetooth
  • 47. Object Model
  • 48. Main Objects CBCentralManager CBCentralManagerDelegate CBPeripheralManager CBPeripheralManagerDelegate Data Objects CBPeripheral CBCentral CBPeripheralDelegate CBMutableService CBService CBMutableCharacteristic CBCharacteristic Helper Objects CBUUID CBATTRequest
  • 49. Being a Central
  • 50. Central Peripheral
  • 51. CBCentralManager Scanning! – scanForPeripheralsWithServices:options ! Stop scanning! – stopScan ! Connecting to peripherals! – connectPeripheral:options – cancelPeripheralConnection: ! Retrieving known peripherals! – retrieveConnectedPeripheralsWithServices: – retrievePeripheralsWithIdentifiers:
  • 52. CBCentralManagerDelegate Monitoring Connections with Peripherals! – centralManager:didConnectPeripheral: – centralManager:didDisconnectPeripheral:error: – centralManager:didFailToConnectPeripheral:error: ! Discovering and Retrieving Peripherals! – centralManager:didDiscoverPeripheral:advertisementData:RSSI: – centralManager:didRetrieveConnectedPeripherals: – centralManager:didRetrievePeripherals: ! Monitoring Changes to the Central Manager’s State! – centralManagerDidUpdateState: – centralManager:willRestoreState:
  • 53. CBPeripheralDelegate Discovering Services! – peripheral:didDiscoverServices: – peripheral:didDiscoverIncludedServicesForService:error: ! Discovering Characteristics and Characteristic Descriptors! – peripheral:didDiscoverCharacteristicsForService:error: – peripheral:didDiscoverDescriptorsForCharacteristic:error: ! Retrieving Characteristic and Characteristic Descriptor Values! – peripheral:didUpdateValueForCharacteristic:error: – peripheral:didUpdateValueForDescriptor:error: ! Writing Characteristic and Characteristic Descriptor Values! – peripheral:didWriteValueForCharacteristic:error: – peripheral:didWriteValueForDescriptor:error: ! Managing Notifications for a Characteristic’s Value! – peripheral:didUpdateNotificationStateForCharacteristic:error: ! Retrieving a Peripheral’s Received Signal Strength Indicator (RSSI) Data! – peripheralDidUpdateRSSI:error: ! Monitoring Changes to a Peripheral’s Name or Services! – peripheralDidUpdateName: – peripheral:didModifyServices:
  • 54. > code <
  • 55. Being a Peripheral
  • 56. Central Peripheral
  • 57. CBPeripheralManager Services! – addService: – removeService: – removeAllServices: ! Advertising! – startAdvertising: – stopAdvertising – isAdvertising ! Notifying observing devices of updates! – updateValue:forCharacteristic:onSubscribedCentrals: ! Responding to Read/Write Requests! – respondToRequest:withResult
  • 58. CBPeripheralManagerDelegate Monitoring Changes to the Peripheral Manager’s State! – peripheralManagerDidUpdateState: – peripheralManager:willRestoreState: ! Adding Services! – peripheralManager:didAddService:error: ! Advertising Peripheral Data! – peripheralManagerDidStartAdvertising:error: ! Monitoring Subscriptions to Characteristic Values! – peripheralManager:central:didSubscribeToCharacteristic: – peripheralManager:central:didUnsubscribeFromCharacteristic: – peripheralManagerIsReadyToUpdateSubscribers: ! Receiving Read and Write Requests! – peripheralManager:didReceiveReadRequest: – peripheralManager:didReceiveWriteRequests:
  • 59. CBMutableService Initializing a Mutable Service! – initWithType:primary: ! Managing a Mutable Service! – UUID – isPrimary – characteristics – includedServices CBMutableCharacteristic Initializing a Mutable Characteristic! – initWithType:properties:value:permissions: ! Managing a Mutable Characteristic! UUID value descriptors properties permissions subscribedCentrals
  • 60. > code <
  • 61. Foreground vs. Background
  • 62. Two background modes.
  • 63. bluetooth-central “Uses Bluetooth LE accessories” in Xcode
  • 64. bluetooth-peripheral “Acts as Bluetooth LE accessory” in Xcode
  • 65. Specify background modes in Info.plist.
  • 66. Nuances of backgrounding
  • 67. Central Scanning • Scanning (as a Central) acts differently in the background. • Scan options are ignored. Multiple discoveries of a peripheral are coalesced into one. • The scan interval may increase and your app may take longer to discover a peripheral.
  • 68. Peripheral Advertising • Advertising in the background differs from foreground mode: • The CBAdvertisementDataLocalNameKey is not advertised. • The frequency at which your app advertises may decrease. • Service UUIDs may not be advertised. Apple does best effort.
  • 69. Peripheral Events • iOS will wake up your app to receive events: read, write, and subscribe events.
  • 70. Caching • Services, characteristics and characteristic descriptors are cached • Characteristic value is kind of cached. When discovered the last read value will be provided, but it’s put to you to use it (static values) or read the value (dynamic values) from the peripheral.
  • 71. State Preservation and Restoration • Optional feature. • Why? if your app is background it can be terminated the OS • iOS will store the state of the application and act on behalf of it as a proxy. When it receives an event your app is waiting for it will start the app back up in the background to allow it to process it • Single method for you to implement to restore the state of your app.
  • 72. iBeacons
  • 73. A part of CoreLocation
  • 74. Just a data format in the advertising packets. ! Apple to release actual profile on ___________.
  • 75. Tips
  • 76. CoreBluetooth lives in IOBluetooth for Mac apps.
  • 77. No more simulator support as of iOS7
  • 78. Keep references to CBPeripheral and CBCentrals if you plan on using them.
  • 79. YOSO! YOCO! DSWYDNT
  • 80. Done with peripheral, disconnect.
  • 81. CBPeripheral and CBCentral objects can be dictionary keys.
  • 82. If you’re a peripheral support characteristic notifications.
  • 83. Require paired connections to acquire sensitive information
  • 84. Finding peripherals the system already knows about CentralManager – retrieveConnectedPeripheralsWithServices: – retrievePeripheralsWithIdentifiers:
  • 85. MTU Exchange Requests *Borrowed from 2013 Apple WWDC talk
  • 86. MTU Exchange Requests • Allows more data to be sent in one go • Less packet overhead • up to 20% increase in throughput • Free.
  • 87. App store recommendations from Apple • include the device with your submission • be explicit about services the device provides • provide instructions for how to use the device/ app • or don’t and cross your fingers
  • 88. @zachdennis @zdennis ! mutuallyhuman.com

×