building ios apps using "bluetooth low energy"
TRANSCRIPT
![Page 1: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/1.jpg)
Building iOS apps using "Bluetooth Low Energy"
Shuichi Tsutsumi @shu223July 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
![Page 2: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/2.jpg)
![Page 4: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/4.jpg)
Overview• Basics of BLE • Practical Tips to build apps using BLE
with Japanse Products
![Page 5: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/5.jpg)
Bluetooth Low Energy?
![Page 6: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/6.jpg)
Bluetooth Low Energy (BLE)• Wireless technology
- no network infrastructure required
Wi-FiBLE
![Page 7: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/7.jpg)
• Low energy
• NOT compatible with Classic BT
• Uses 2.4 GHz radio frequencies
• Marketed by the Bluetooth SIG
• etc…
![Page 8: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/8.jpg)
The most important thing (for iOS developers)
![Page 9: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/9.jpg)
The iOS API ‘Core Bluetooth’ is open for developers
• API for Classic BT is NOT open.
- Requires MFi certification.
![Page 10: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/10.jpg)
BLE is almost the ONLY way to enable iOS apps to communicate
with external hardware without infrastructure or MFi.
![Page 11: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/11.jpg)
fuelband estimote konashi moff band sensortag
fuelband estimote 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
![Page 12: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/12.jpg)
Basics of BLE
![Page 14: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/14.jpg)
(Demo)
![Page 15: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/15.jpg)
Moff Band Moff App
Sensor Data
BLE Connection
Sensors - Gyroscope - Accelerometer
Analyze sensor data
Recognize - Gesture - Posture
Play sounds
![Page 16: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/16.jpg)
Sensor Data
BLE Connection
How is sensor data sent to the app?
![Page 17: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/17.jpg)
Scan
Step 1. Scan
Advertise
: Search for nearby BLE devices
centralManager.scanForPeripheralsWithServices(nil, options: nil)
Peripheral Central
![Page 18: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/18.jpg)
Connect
Step 2. Connect
centralManager.connectPeripheral(peripheral, options: nil)
![Page 19: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/19.jpg)
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)
![Page 20: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/20.jpg)
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!”) }
![Page 21: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/21.jpg)
Hardware Side?I’m sorry, I don’t know…
![Page 22: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/22.jpg)
BLE
Firmware Engineer iOS Engineer
![Page 23: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/23.jpg)
Japanese Hardware Products
I’ve worked on
![Page 24: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/24.jpg)
![Page 25: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/25.jpg)
![Page 26: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/26.jpg)
![Page 27: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/27.jpg)
![Page 28: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/28.jpg)
![Page 29: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/29.jpg)
![Page 30: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/30.jpg)
![Page 31: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/31.jpg)
![Page 32: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/32.jpg)
![Page 33: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/33.jpg)
Group conversation system with VoIP
- Detects the human voice
- Cuts out all background noise
→ Can be used even in areas with poor coverage!
![Page 34: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/34.jpg)
BLE for BONX
![Page 36: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/36.jpg)
Printable Open-Source Humanoid “PLEN2”
![Page 37: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/37.jpg)
Music for the DeafDaito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY
![Page 38: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/38.jpg)
Music for the DeafDaito Manabe/Motoi Ishibashi/Teruoka Masaki/Shuichi Tsutsumi x SOUL FAMILY
Commands
Electronic Stimulation DeviceiPhone
![Page 39: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/39.jpg)
![Page 40: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/40.jpg)
Practical Tips to build apps using BLE
![Page 41: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/41.jpg)
Defining GATT
![Page 42: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/42.jpg)
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
![Page 43: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/43.jpg)
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
![Page 44: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/44.jpg)
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
![Page 45: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/45.jpg)
How to define GATT1. 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
![Page 46: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/46.jpg)
Reference: GATT profiles by Bluetooth SIG
![Page 47: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/47.jpg)
Defining background behaviors
![Page 48: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/48.jpg)
Background behaviors on iOS• Very limited
- Listening to music
- Getting location data
- Downloading data
![Page 49: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/49.jpg)
Imagine
![Page 50: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/50.jpg)
If BLE didn’t work in the background…
![Page 51: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/51.jpg)
You would have to always keep the app in the foreground, while snowboarding!
![Page 52: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/52.jpg)
You would have to launch the app whenever you go driving!
![Page 53: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/53.jpg)
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!
![Page 54: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/54.jpg)
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)
![Page 55: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/55.jpg)
If the app in the background is killed by the system…
![Page 56: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/56.jpg)
![Page 57: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/57.jpg)
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!
![Page 58: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/58.jpg)
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!
![Page 59: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/59.jpg)
How to test without HW prototypes
![Page 60: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/60.jpg)
Did the HW prototypes exist when develop the apps?
Projects HW prototypes existed?
Moff YES
WHILL NOBONX NOSmartDrive YES
PLEN2 NOMusic for the Deaf NO
![Page 61: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/61.jpg)
Development Kit
Can start development without creating a circuit ourselves
BLE ModuleDisplay
USB interface
Battery box
![Page 62: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/62.jpg)
Horizontal (-100~100) / Vertical (-100~100)
Development Kit AppBLE
![Page 63: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/63.jpg)
![Page 64: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/64.jpg)
Emulator App
• Develop another iOS app as the alternative to the peripheral device
• Easier for iOS engineers
![Page 65: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/65.jpg)
Multi-Function Control • Single Tap • Double Tap • Long Press • Very Long Press
=
![Page 66: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/66.jpg)
App Review
![Page 67: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/67.jpg)
Costing too much
MSRP $13,995
Not enough devices when submitting
![Page 68: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/68.jpg)
Videos for review
• Show how the app works with the peripheral device • Not need to be cool!
![Page 69: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/69.jpg)
• Shoot with iPhone • Edit with iMovie
![Page 70: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/70.jpg)
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
![Page 71: Building iOS apps using "Bluetooth Low Energy"](https://reader031.vdocument.in/reader031/viewer/2022022414/5872c7411a28ab0c718b671b/html5/thumbnails/71.jpg)
Thank you!Shuichi Tsutsumi - iOS Freelancer
• Twitter: @shu223
• GitHub: shu223
• Email: [email protected]