Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

1,116 views

Published on

n recent years, "IoT" or "Wearable" are one of buzzwords, so you might have interests in building hardware products. But learning how to develop electric circuits, mechanical systems or embedded systems etc. from zero is so difficult.

However, iOS developers can contribute to projects of hardware products with the knowledge of Core Bluetooth / Bluetooth Low Energy (BLE), even if they are not familiar with hardware layer.

In this session, you can learn the basics of Core Bluetooth / BLE (what it is, why we use it, and how it works), and practical knowledges to build apps for hardware products (how to design the apps, how to test without actual hardware prototypes, troubleshooting tips, and how the apps can be reviewed by Apple) which I learned through actual IoT/Wearable projects.

This would be interesting & understandable even if you are not familiar with or have no interests in Core Bluetooth because of the actual examples.

Published in: Technology

Practical Core Bluetooth in IoT & Wearable projects @ AltConf 2016

  1. 1. Practical Core Bluetooth in IoT & Wearable projects Shuichi Tsutsumi @shu223 AltConf 2016 - San Francisco
  2. 2. iOS-10-Sampler https://github.com/shu223
  3. 3. Overview • Basics of Core Bluetooth • Practical Core Bluetooth Based on my experience!
  4. 4. Bluetooth Low Energy?
  5. 5. Bluetooth Low Energy (BLE)
  6. 6. Bluetooth Low Energy (BLE) • Wireless technology
  7. 7. Bluetooth Low Energy (BLE) • Wireless technology - no network infrastructure required
  8. 8. Bluetooth Low Energy (BLE) • Wireless technology - no network infrastructure required Wi-Fi
  9. 9. Bluetooth Low Energy (BLE) • Wireless technology - no network infrastructure required BLE
  10. 10. • Low energy
  11. 11. • Low energy • NOT compatible with Classic BT
  12. 12. • Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies
  13. 13. • Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies • Marketed by the Bluetooth SIG
  14. 14. • Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies • Marketed by the Bluetooth SIG • etc…
  15. 15. • Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies • Marketed by the Bluetooth SIG • etc…
  16. 16. The most important thing for iOS developers
  17. 17. The API ‘Core Bluetooth’ is open for developers
  18. 18. The API ‘Core Bluetooth’ is open for developers • API for Classic BT is NOT open. - Requires MFi certification.
  19. 19. BLE is almost the ONLY way to enable iOS apps to communicate with external hardware without infrastructure or MFi.
  20. 20. Basics of Core Bluetooth
  21. 21. Moff Band Moff App
  22. 22. Moff Band Moff App BLE Connection
  23. 23. Moff Band Moff App BLE Connection Sensors - Gyroscope - Accelerometer
  24. 24. Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer
  25. 25. Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer Analyze sensor data
  26. 26. Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer Analyze sensor data Recognize - Gesture - Posture
  27. 27. Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer Analyze sensor data Recognize - Gesture - Posture Play sounds
  28. 28. Sensor Data BLE Connection How is sensor data sent with Core Bluetooth?
  29. 29. Step 1. Scan
  30. 30. Step 1. Scan: Search for nearby BLE devices
  31. 31. Step 1. Scan: Search for nearby BLE devices
  32. 32. Step 1. Scan Advertise : Search for nearby BLE devices
  33. 33. Scan Step 1. Scan Advertise : Search for nearby BLE devices
  34. 34. Scan Step 1. Scan Advertise : Search for nearby BLE devices centralManager.scanForPeripheralsWithServices(nil, options: nil)
  35. 35. Scan Step 1. Scan Advertise Discover : Search for nearby BLE devices
  36. 36. Scan Step 1. Scan Advertise Discover : Search for nearby BLE devices func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(“Discovered a BLE device!”) }
  37. 37. Scan Step 1. Scan Advertise Discover : Search for nearby BLE devices func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(“Discovered a BLE device!”) } Central
  38. 38. Scan Step 1. Scan Advertise Discover : Search for nearby BLE devices func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(“Discovered a BLE device!”) } Peripheral Central
  39. 39. Step 2. Connect
  40. 40. Connect Step 2. Connect
  41. 41. Connect Step 2. Connect centralManager.connectPeripheral(peripheral, options: nil)
  42. 42. Connect Step 2. Connect centralManager.connectPeripheral(peripheral, options: nil) func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) { print(“Connected!”) }
  43. 43. Step 3. Subscribe
  44. 44. Step 3. Subscribe: Ready to receive data
  45. 45. Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile
  46. 46. Moff Service xx Service Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile
  47. 47. Moff Service xx Service Button Characteristic xx Characteristic Sensor Characteristic Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile
  48. 48. Moff Service xx Service Button Characteristic xx Characteristic Sensor Characteristic Subscribe (Request to be notified) Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile
  49. 49. Moff Service xx Service Button Characteristic xx Characteristic Sensor Characteristic Subscribe (Request to be notified) Step 3. Subscribe: Ready to receive data GATT = Generic Attribute Profile peripheral.setNotifyValue(true, forCharacteristic: c)
  50. 50. Step 4. Notify Moff Service Sensor Characteristic xxxx Characteristic
  51. 51. Step 4. Notify Moff Service Sensor Characteristic xxxx Characteristic Update the value
  52. 52. Step 4. Notify Notify subscribers Moff Service Sensor Characteristic xxxx Characteristic Update the value
  53. 53. Step 4. Notify Notify subscribers Moff Service Sensor Characteristic xxxx Characteristic Update the value func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received sensor data!”) }
  54. 54. Step 4. Notify Notify subscribers Moff Service Sensor Characteristic xxxx Characteristic Update the value func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received sensor data!”) }
  55. 55. Hardware Side?
  56. 56. Hardware Side? I’m sorry, I don’t know…
  57. 57. BLE
  58. 58. BLE iOS Engineer
  59. 59. BLE iOS Engineer
  60. 60. BLE Firmware Engineer iOS Engineer
  61. 61. BLE Firmware Engineer iOS Engineer
  62. 62. Hardware Projects I’ve worked on as an iOS engineer
  63. 63. Wheelchair ‘WHILL’
  64. 64. Wheelchair ‘WHILL’
  65. 65. Wearable Walkie-Talkie ‘BONX’
  66. 66. Wearable Walkie-Talkie ‘BONX’
  67. 67. Wearable Walkie-Talkie ‘BONX’
  68. 68. Group conversation system with VoIP
  69. 69. Group conversation system with VoIP - Detects the human voice
  70. 70. Group conversation system with VoIP - Detects the human voice - Cuts out all background noise
  71. 71. Group conversation system with VoIP - Detects the human voice - Cuts out all background noise → Can be used even in areas with poor coverage!
  72. 72. BLE for BONX
  73. 73. BLE for BONX
  74. 74. BLE for BONX
  75. 75. BLE for BONX
  76. 76. IoT for Cars ‘SmartDrive’
  77. 77. Printable Open-Source Humanoid “PLEN2”
  78. 78. Music for the Deaf Daito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY
  79. 79. Music for the Deaf Daito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY iPhone
  80. 80. Music for the Deaf Daito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY Electronic Stimulation DeviceiPhone
  81. 81. Music for the Deaf Daito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY Commands Electronic Stimulation DeviceiPhone
  82. 82. Music for the Deaf Daito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY
  83. 83. Practical Core Bluetooth
  84. 84. Defining GATT
  85. 85. GATT to send sensor data Foo Service Sensor Data Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Bar Service xx Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each) xx Characteristic
  86. 86. GATT to send sensor data Foo Service Sensor Data Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Bar Service xx Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each) xx Characteristic
  87. 87. GATT to send sensor data Foo Service Sensor Data Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Bar Service xx Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each) xx Characteristic
  88. 88. GATT to send sensor data Foo Service Sensor Data Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Bar Service xx Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each) xx Characteristic
  89. 89. GATT to send sensor data Foo Service Sensor Data Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Bar Service xx Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each) xx Characteristic
  90. 90. GATT to send sensor data Foo Service Sensor Data Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Bar Service xx Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: acc x, acc y, acc z, gyro x, gyro y, gyro z (2bytes for each) xx Characteristic
  91. 91. GATT to send button interactions Foo Service Button Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: 0x01 or 0x00
  92. 92. GATT to send button interactions Foo Service Button Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: 0x01 or 0x00
  93. 93. GATT to send button interactions Foo Service Button Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: 0x01 or 0x00
  94. 94. GATT to send button interactions Foo Service Button Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: 0x01 or 0x00 Button interactions
  95. 95. GATT to send button interactions Foo Service Button Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: 0x01 or 0x00 Button interactions
  96. 96. GATT to send button interactions Foo Service Button Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: 0x01 or 0x00 Button interactions
  97. 97. GATT to send button interactions Foo Service Button Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Notify Value: 0x01 or 0x00 Button interactions 0x01: Pushed 0x00: Released
  98. 98. GATT for remote control Foo Service Remote Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100)
  99. 99. GATT for remote control Foo Service Remote Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100)
  100. 100. GATT for remote control Foo Service Remote Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100) values
  101. 101. GATT for remote control Foo Service Remote Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100) values
  102. 102. GATT for remote control Foo Service Remote Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: Horizontal (-100 ~ 100), Vertical (-100 ~ 100) values
  103. 103. GATT for generic commands
  104. 104. GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte
  105. 105. GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte
  106. 106. GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte 4 Commands: - Change the pulse frequency - Change the electric current - Right channels on/off - Left channels on/off
  107. 107. GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte 4 Commands: - Change the pulse frequency - Change the electric current - Right channels on/off - Left channels on/off
  108. 108. GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte High-order 2 bits - 00: Change the pulse frequency - 01: Change the electric current - 10: Left channels on/off - 11: Right channels on/off
  109. 109. GATT for generic commands Electronic Stimulation Control Characteristic UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Properties: Write Value: 1 byte High-order 2 bits - 00: Change the pulse frequency - 01: Change the electric current - 10: Left channels on/off - 11: Right channels on/off
  110. 110. How to define GATT
  111. 111. How to define GATT 1. Create UUID for the service & characteristic
  112. 112. How to define GATT 1. Create UUID for the service & characteristic $ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C
  113. 113. How to define GATT 1. Create UUID for the service & characteristic 2. Define the properties (Read, Notify, Write, etc.) $ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C
  114. 114. How to define GATT 1. Create UUID for the service & characteristic 2. Define the properties (Read, Notify, Write, etc.) Peripheral → Central: Notify 
 Central → Peripheral: Write $ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C
  115. 115. How to define GATT 1. Create UUID for the service & characteristic 2. Define the properties (Read, Notify, Write, etc.) Peripheral → Central: Notify 
 Central → Peripheral: Write 3. Define the value format $ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C
  116. 116. How to define GATT 1. Create UUID for the service & characteristic 2. Define the properties (Read, Notify, Write, etc.) Peripheral → Central: Notify 
 Central → Peripheral: Write 3. Define the value format Usually limited to 20 bytes $ uuidgen CEEA31BC-BEAC-4A78-B7ED-FC96B6254D4C
  117. 117. Reference: GATT profiles by Bluetooth SIG
  118. 118. Defining background behaviors
  119. 119. Background behaviors on iOS • Very limited - Listening to music - Getting location data - Downloading data
  120. 120. Imagine
  121. 121. If BLE didn’t work in the background…
  122. 122. You would have to always keep the app in the foreground, while snowboarding!
  123. 123. You would have to launch the app whenever you go driving!
  124. 124. What functions can be used in the background?
  125. 125. What functions can be used in the background? • Scanning peripherals
  126. 126. What functions can be used in the background? • Scanning peripherals • Connecting with peripherals
  127. 127. What functions can be used in the background? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value
  128. 128. What functions can be used in the background? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value • Writing characteristics’ value
  129. 129. What functions can be used in the background? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value • Writing characteristics’ value • Receiving notifications
  130. 130. What functions can be used in the background? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value • Writing characteristics’ value • Receiving notifications Almost all functions can be used even in the background!
  131. 131. How to support background mode
  132. 132. Just check this box!
  133. 133. Limitations
  134. 134. Limitations • Longer intervals for scanning
  135. 135. Limitations • Longer intervals for scanning • Must explicitly specify one or more services to scan
  136. 136. Limitations • Longer intervals for scanning • Must explicitly specify one or more services to scan • CBCentralManagerOptionShowPowerAlertKey option is ignored
  137. 137. Limitations • Longer intervals for scanning • Must explicitly specify one or more services to scan • CBCentralManagerOptionShowPowerAlertKey option is ignored Resources - Core Bluetooth Programming Guide - Core Bluetooth Framework Reference (also in headers)
  138. 138. If the app in the background is killed by the system…
  139. 139. State Preservation and Restoration
  140. 140. State Preservation and Restoration The system takes over the BLE tasks even after the app is killed.
  141. 141. State Preservation and Restoration The system takes over the BLE tasks even after the app is killed. - Preserves the state of the app’s central managers and continues the BLE tasks on their behalf.
  142. 142. State Preservation and Restoration The system takes over the BLE tasks even after the app is killed. - Preserves the state of the app’s central managers and continues the BLE tasks on their behalf. - Relaunches the app into the background and calls the corresponding delegate method.
  143. 143. State Preservation and Restoration The system takes over the BLE tasks even after the app is killed. - Preserves the state of the app’s central managers and continues the BLE tasks on their behalf. - Relaunches the app into the background and calls the corresponding delegate method. → The app can handle BLE events!
  144. 144. • The app is killed by the system
  145. 145. • The app is killed by the system • The user pushes the button on the peripheral device
  146. 146. • The app is killed by the system • The user pushes the button on the peripheral device • The system receives the notification
  147. 147. • The app is killed by the system • The user pushes the button on the peripheral device • The system receives the notification • The app is relaunched in the BG and the delegate method is called.
  148. 148. func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received the characteristic data!”) } • The app is killed by the system • The user pushes the button on the peripheral device • The system receives the notification • The app is relaunched in the BG and the delegate method is called.
  149. 149. func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { print(“Received the characteristic data!”) } • The app is killed by the system • The user pushes the button on the peripheral device • The system receives the notification • The app is relaunched in the BG and the delegate method is called. The app can process the button interaction!
  150. 150. Implementation
  151. 151. Implementation • Add an option when initializing the CBCentralManager object. let options = [ CBCentralManagerOptionRestoreIdentifierKey: "somekey" ] centralManager = CBCentralManager( delegate: self, queue: queue, options: options)
  152. 152. Implementation • Implement the delegate method which is called when the app is restored. func centralManager(central: CBCentralManager, willRestoreState dict: [String : AnyObject]) { print("Restored") }
  153. 153. Testing the restoration
  154. 154. Testing the restoration • Kill the app as if it was killed by the iOS kill(getpid(), SIGKILL);
  155. 155. How to test without HW prototypes
  156. 156. Did the HW prototypes exist when develop the apps? Projects HW prototypes existed? Moff YES WHILL NO BONX NO SmartDrive YES PLEN2 NO Music for the Deaf NO
  157. 157. Development Kit
  158. 158. Development Kit BLE Module
  159. 159. Development Kit BLE Module Display
  160. 160. Development Kit BLE Module Display USB interface
  161. 161. Development Kit BLE Module Display USB interface Battery box
  162. 162. Development Kit Can start development without creating a circuit ourselves BLE Module Display USB interface Battery box
  163. 163. Development Kit
  164. 164. Development Kit App
  165. 165. Development Kit App BLE
  166. 166. Horizontal (-100~100) / Vertical (-100~100) Development Kit App BLE
  167. 167. Emulator App
  168. 168. Emulator App • Develop another iOS app as the alternative to the peripheral device
  169. 169. Emulator App • Develop another iOS app as the alternative to the peripheral device • Use CBPeripheralManager
  170. 170. Emulator App • Develop another iOS app as the alternative to the peripheral device • Use CBPeripheralManager • Easier for iOS engineers
  171. 171. =
  172. 172. Multi-Function Control • Single Tap • Double Tap • Long Press • Very Long Press =
  173. 173. Troubleshooting
  174. 174. Can’t find the peripheral Scan ?
  175. 175. Can’t connect Find
  176. 176. Can’t connect Connect ×
  177. 177. • Connection dropped
  178. 178. • Connection dropped • Can’t discover services or characteristics
  179. 179. • Connection dropped • Can’t discover services or characteristics • Fail to write
  180. 180. • Connection dropped • Can’t discover services or characteristics • Fail to write • Incorrect characteristic values
  181. 181. • Connection dropped • Can’t discover services or characteristics • Fail to write • Incorrect characteristic values • Incorrect behaviors in the background
  182. 182. • Connection dropped • Can’t discover services or characteristics • Fail to write • Incorrect characteristic values • Incorrect behaviors in the background • etc…
  183. 183. Identify which side the problem is on Is the problem on the central side or on the peripheral side? → Compare with another iOS app like ‘LightBlue’
  184. 184. Can’t find the peripheral • Scanning, but can’t find the peripheral device
  185. 185. Can’t find the peripheral • Scanning, but can’t find the peripheral device Scan
  186. 186. Can’t find the peripheral • Scanning, but can’t find the peripheral device Scan but ‘didDiscover’ method isn’t called
  187. 187. Can’t find the peripheral • Scan with another iOS app Scan
  188. 188. Can’t find the peripheral • Scan with another iOS app Scan Discovered peripherals
  189. 189. Can’t connect, etc. Connect
  190. 190. Can’t connect, etc. Connect Services & Characteristics
  191. 191. Other debugging tools
  192. 192. Bluetooth Explorer macOS app made by Apple
  193. 193. Low Energy Devices
  194. 194. Low Energy Devices Scan, Connect
  195. 195. Low Energy Devices Scan, Connect Details of services and characteristics
  196. 196. Low Energy Devices Scan, Connect Details of services and characteristics Write, Read, Subscribe
  197. 197. func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) }
  198. 198. func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) } Filtered by iOS!
  199. 199. func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) } Filtered by iOS! → Can’t see all of the advertisement data
  200. 200. func centralManager( central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber!) { print(advertisementData) } Filtered by iOS! → Can’t see all of the advertisement data e.g. Can’t see the ‘Manufacture Data’ field of iBeacon
  201. 201. Not filtered →Can see the ‘Manufacture Data’ field of iBeacon
  202. 202. Packet Logger macOS app made by Apple
  203. 203. How to get
  204. 204. How to get Download ‘Hardware IO Tools for Xcode’
  205. 205. How to get Download ‘Hardware IO Tools for Xcode’
  206. 206. How to get Download ‘Hardware IO Tools for Xcode’
  207. 207. How to get Download ‘Hardware IO Tools for Xcode’
  208. 208. App Review
  209. 209. MSRP $13,995
  210. 210. Costing too much
  211. 211. Not enough devices when submitting
  212. 212. Videos for review
  213. 213. Videos for review • Show how the app works with the peripheral device
  214. 214. Videos for review • Show how the app works with the peripheral device • Not need to be cool!
  215. 215. • Shoot with iPhone
  216. 216. • Shoot with iPhone • Edit with iMovie
  217. 217. Recap
  218. 218. Recap • What is Bluetooth Low Energy?
  219. 219. Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product
  220. 220. Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples
  221. 221. Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples - Defining GATT
  222. 222. Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples - Defining GATT - Defining background behaviors
  223. 223. Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples - Defining GATT - Defining background behaviors - Testing without HW prototypes
  224. 224. Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples - Defining GATT - Defining background behaviors - Testing without HW prototypes - Troubleshooting
  225. 225. Recap • What is Bluetooth Low Energy? • Basics of Core Bluetooth with an actual product • Practical Core Bluetooth with specific examples - Defining GATT - Defining background behaviors - Testing without HW prototypes - Troubleshooting - App Review
  226. 226. Core Bluetooth in iOS 10
  227. 227. Nothing special
  228. 228. CBManager
  229. 229. func centralManagerDidUpdateState(_ central: CBCentralManager) { print("state: (central.state)") }
  230. 230. Initializer without arguments
  231. 231. private var centralManager: CBCentralManager! override func viewDidLoad() { super.viewDidLoad() centralManager = CBCentralManager(delegate: self, queue: nil) } From
  232. 232. private let centralManager = CBCentralManager() override func viewDidLoad() { super.viewDidLoad() centralManager.delegate = self } private var centralManager: CBCentralManager! override func viewDidLoad() { super.viewDidLoad() centralManager = CBCentralManager(delegate: self, queue: nil) } From To
  233. 233. Thank you! Shuichi Tsutsumi - iOS Freelancer • Twitter: @shu223 • GitHub: shu223 • Blog: https://medium.com/@shu223/ • Email: shuichi0526@gmail.com

×