Successfully reported this slideshow.
Your SlideShare is downloading. ×

BTLE (Bluetooth Low Energy) and CoreBluetooth

Ad

Bluetooth LE,
CoreBluetooth
@zachdennis
@zdennis
!

mutuallyhuman.com

Ad

Bluetooth LE

Ad

What is BTLE?

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Loading in …3
×

Check these out next

1 of 90 Ad
1 of 90 Ad

BTLE (Bluetooth Low Energy) and CoreBluetooth

Download to read offline

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.

Advertisement
Advertisement

More Related Content

Advertisement
Advertisement

BTLE (Bluetooth Low Energy) and CoreBluetooth

  1. 1. Bluetooth LE, CoreBluetooth @zachdennis @zdennis ! mutuallyhuman.com
  2. 2. Bluetooth LE
  3. 3. What is BTLE?
  4. 4. A short range, ultra-low power consuming wireless technology.
  5. 5. Shares the “Bluetooth” name, but has different design goals in mind.
  6. 6. Power Consumption Years, not hours or days.
  7. 7. Short range ~ 50m
  8. 8. Packet-based Short bursts of data.
  9. 9. Intervals Ad Ad Data Ad Data
  10. 10. Multiple channels #1 Ad Ad Data Ad Data #2 Ad Ad Data Ad Data #3 Ad Ad Data Ad Data
  11. 11. Device A is looking. Scan Scan Data Ad Ad Data Ad Data Ad Ad Data Ad Data Device B is advertising.
  12. 12. Frequency hopping
  13. 13. Connection-less Devices do not need to maintain connections.
  14. 14. Pairing e.g. iOS - happens when Insufficient Authentication error code is sent from the peripheral.
  15. 15. Security Devices pair, keys are distributed, and the connection is encrypted. ! Encryption is AES-128.
  16. 16. Why BTLE?
  17. 17. *Borrowed from 2012 WWDC CoreBluetooth Talk
  18. 18. 1 billion+ devices
  19. 19. *Borrowed from 2013 Apple WWDC talk
  20. 20. How BTLE Works
  21. 21. The Stack
  22. 22. Key Terms • Central • Peripheral • Service • Characteristic • Descriptor
  23. 23. Central (wants data) Peripheral (has data)
  24. 24. Central Peripheral advertising
  25. 25. Central Peripheral advertising scan
  26. 26. Central Peripheral advertising scan advertising
  27. 27. Central Peripheral advertising scan advertising discover services Heart Monitor
  28. 28. Central Peripheral advertising scan advertising discover services Heart Monitor discover characteristics BPM
  29. 29. Central Peripheral advertising scan advertising discover services Heart Monitor discover characteristics BPM read value 95
  30. 30. Central Peripheral advertising scan advertising discover services Heart Monitor discover characteristics BPM read value 95 observe value BPM 95
  31. 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. 32. Service A service is a human-readable specification of a set of characteristics and their associated behavior.
  33. 33. Two kinds of services There are primary services and secondary services.
  34. 34. Nested services Services can contain other services.
  35. 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. 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. 37. Heart Rate Profile Collector Heart Rate Sensor Heart Rate Service Device Information Service
  38. 38. Heart Rate Profile GATT CLIENT GATT SERVER Collector Heart Rate Sensor Heart Rate Service Device Information Service
  39. 39. Profiles & Services Profiles contain services. Services can be contained by multiple profiles.
  40. 40. Anatomy of a Peripheral Peripheral Service Characteristic Descriptor Characteristic Service Characteristic
  41. 41. Apple’s Approach to BTLE
  42. 42. Simple Powerful
  43. 43. Technology Stack
  44. 44. *Borrowed from 2012 WWDC CoreBluetooth Talk
  45. 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. 46. CoreBluetooth
  47. 47. Object Model
  48. 48. Main Objects CBCentralManager CBCentralManagerDelegate CBPeripheralManager CBPeripheralManagerDelegate Data Objects CBPeripheral CBCentral CBPeripheralDelegate CBMutableService CBService CBMutableCharacteristic CBCharacteristic Helper Objects CBUUID CBATTRequest
  49. 49. Being a Central
  50. 50. Central Peripheral
  51. 51. CBCentralManager Scanning! – scanForPeripheralsWithServices:options ! Stop scanning! – stopScan ! Connecting to peripherals! – connectPeripheral:options – cancelPeripheralConnection: ! Retrieving known peripherals! – retrieveConnectedPeripheralsWithServices: – retrievePeripheralsWithIdentifiers:
  52. 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. 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. 54. > code <
  55. 55. Being a Peripheral
  56. 56. Central Peripheral
  57. 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. 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. 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. 60. > code <
  61. 61. Foreground vs. Background
  62. 62. Two background modes.
  63. 63. bluetooth-central “Uses Bluetooth LE accessories” in Xcode
  64. 64. bluetooth-peripheral “Acts as Bluetooth LE accessory” in Xcode
  65. 65. Specify background modes in Info.plist.
  66. 66. Nuances of backgrounding
  67. 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. 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. 69. Peripheral Events • iOS will wake up your app to receive events: read, write, and subscribe events.
  70. 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. 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. 72. iBeacons
  73. 73. A part of CoreLocation
  74. 74. Just a data format in the advertising packets. ! Apple to release actual profile on ___________.
  75. 75. Tips
  76. 76. CoreBluetooth lives in IOBluetooth for Mac apps.
  77. 77. No more simulator support as of iOS7
  78. 78. Keep references to CBPeripheral and CBCentrals if you plan on using them.
  79. 79. YOSO! YOCO! DSWYDNT
  80. 80. Done with peripheral, disconnect.
  81. 81. CBPeripheral and CBCentral objects can be dictionary keys.
  82. 82. If you’re a peripheral support characteristic notifications.
  83. 83. Require paired connections to acquire sensitive information
  84. 84. Finding peripherals the system already knows about CentralManager – retrieveConnectedPeripheralsWithServices: – retrievePeripheralsWithIdentifiers:
  85. 85. MTU Exchange Requests *Borrowed from 2013 Apple WWDC talk
  86. 86. MTU Exchange Requests • Allows more data to be sent in one go • Less packet overhead • up to 20% increase in throughput • Free.
  87. 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. 88. @zachdennis @zdennis ! mutuallyhuman.com

×