Building iOS apps using "Bluetooth Low Energy"

140 views

Published on

I gave this talk in Jerusalem, Israel, and Palestine in 2016 with following schedule:

- July 25, 2016 Azrieli College, Jerusalem
- July 26, 2016 Google Campus - Tel Aviv, Israel
- July 27, 2016 SigmaLabs - Tel Aviv, Israel
- July 28, 2016 Birzeit University - Palestine

These events were hosted by Embassy of Japan in Israel.


[Description]

While introducing Japanese technologies (products) such as WHILL, Moff, BONX, and etc. which Mr. Tsutsumi was involved in inventing the applications, he will talk about how BLE, a key technology of IoT, is utilized in those products.

Published in: Mobile
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
140
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Building iOS apps using "Bluetooth Low Energy"

  1. 1. Building iOS apps using "Bluetooth Low Energy" Shuichi Tsutsumi @shu223 July 25, 2016 Azrieli College, Jerusalem July 26, 2016 Google Campus - Tel Aviv, Israel July 27, 2016 SigmaLabs - Tel Aviv, Israel July 28, 2016 Birzeit University - Palestine
  2. 2. Overview • Basics of BLE • Practical Tips to build apps using BLE with Japanse Products
  3. 3. Bluetooth Low Energy?
  4. 4. Bluetooth Low Energy (BLE) • Wireless technology - no network infrastructure required Wi-FiBLE
  5. 5. • Low energy • NOT compatible with Classic BT • Uses 2.4 GHz radio frequencies • Marketed by the Bluetooth SIG • etc…
  6. 6. The most important thing (for iOS developers)
  7. 7. The iOS API ‘Core Bluetooth’ is open for developers • API for Classic BT is NOT open. - Requires MFi certification.
  8. 8. BLE is almost the ONLY way to enable iOS apps to communicate with external hardware without infrastructure or MFi.
  9. 9. konashi moff band sensortag External HW • Simple → Small, Low cost & Long life Smart Phone • High Performance • Internet Connection • Easy to program • etc… Communicate with BLE
  10. 10. Basics of BLE
  11. 11. (Demo)
  12. 12. Moff Band Moff App Sensor Data BLE Connection Sensors - Gyroscope - Accelerometer Analyze sensor data Recognize - Gesture - Posture Play sounds
  13. 13. Sensor Data BLE Connection How is sensor data sent to the app?
  14. 14. Scan Step 1. Scan Advertise : Search for nearby BLE devices centralManager.scanForPeripheralsWithServices(nil, options: nil) Peripheral Central
  15. 15. Connect Step 2. Connect centralManager.connectPeripheral(peripheral, options: nil)
  16. 16. 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)
  17. 17. 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!”) }
  18. 18. Hardware Side? I’m sorry, I don’t know…
  19. 19. BLE Firmware Engineer iOS Engineer
  20. 20. Japanese Hardware Products I’ve worked on
  21. 21. Group conversation system with VoIP - Detects the human voice - Cuts out all background noise → Can be used even in areas with poor coverage!
  22. 22. BLE for BONX
  23. 23. IoT for Cars ‘SmartDrive’
  24. 24. Printable Open-Source Humanoid “PLEN2”
  25. 25. Music for the Deaf Daito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY
  26. 26. Music for the Deaf Daito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY Commands Electronic Stimulation DeviceiPhone
  27. 27. Practical Tips to build apps using BLE
  28. 28. Defining GATT
  29. 29. 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
  30. 30. 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
  31. 31. 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
  32. 32. 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
  33. 33. Reference: GATT profiles by Bluetooth SIG
  34. 34. Defining background behaviors
  35. 35. Background behaviors on iOS • Very limited - Listening to music - Getting location data - Downloading data
  36. 36. Imagine
  37. 37. If BLE didn’t work in the background…
  38. 38. You would have to always keep the app in the foreground, while snowboarding!
  39. 39. You would have to launch the app whenever you go driving!
  40. 40. What functions can be used in the background in iOS? • Scanning peripherals • Connecting with peripherals • Reading characteristics’ value • Writing characteristics’ value • Receiving notifications Almost all functions can be used even in the background!
  41. 41. 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)
  42. 42. If the app in the background is killed by the system…
  43. 43. 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 callback method. → The app can handle BLE events!
  44. 44. 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!
  45. 45. How to test without HW prototypes
  46. 46. 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
  47. 47. Development Kit Can start development without creating a circuit ourselves BLE Module Display USB interface Battery box
  48. 48. Horizontal (-100~100) / Vertical (-100~100) Development Kit App BLE
  49. 49. Emulator App • Develop another iOS app as the alternative to the peripheral device • Easier for iOS engineers
  50. 50. Multi-Function Control • Single Tap • Double Tap • Long Press • Very Long Press =
  51. 51. App Review
  52. 52. Costing too much MSRP $13,995 Not enough devices when submitting
  53. 53. Videos for review • Show how the app works with the peripheral device • Not need to be cool!
  54. 54. • Shoot with iPhone • Edit with iMovie
  55. 55. Recap • What is Bluetooth Low Energy? • Basics of BLE with ‘Moff’. • Japanese Hardware Products I’ve worked on • Practical Tips to build apps using BLE - Defining GATT - Defining background behaviors - Testing without HW prototypes - App Review
  56. 56. Thank you! Shuichi Tsutsumi - iOS Freelancer • Twitter: @shu223 • GitHub: shu223 • Email: shuichi0526@gmail.com

×