Presentation to Ann Arbor CocoaHeads user group in Ann Arbor Michigan on May 14, 2015.
Bluetooth Low Energy (BLE) has become a ubiquitous standard for connecting devices of all types to each other and to cloud services. Mobile apps can leverage BLE in a variety of ways, for example by adding proximity and context via iBeacons, interfacing with Bluetooth peripherals, and adding real-time wireless control over Bluetooth-enabled machines and devices.
This developer-focused session will provide an overview of use cases and capabilities BLE enables for app developers. After a concept introduction, we'll dive into the code required to add BLE capabilities, and finally demonstrate BLE-enabled apps that interface with microcontrollers and iBeacons. Code and demos will use iOS and Swift, but the concepts and techniques apply equally to OSX and Android platforms.
About Robert Kerr
Rob is the founder of Mobile Toolworks, where he helps startup and established companies reinvent their businesses using cloud-enabled mobile technologies.
Rob became an entrepreneur early on, starting a custom software business while in college. Subsequently he played instrumental roles helping build a series of successful technology companies.
He received a degree in Computer Information Systems from Western Michigan University, holds patents in connected device sensor analysis, was awarded Microsoft's Most Valued Professional (MVP) for his tech community contributions, and held software engineering, consulting and executive-level management positions prior to founding Mobile Toolworks.
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Use Bluetooth to connect your iOS app to the Internet of Things
1. Using Bluetooth to connect your
iOS app to The Internet of
Things
Robert Kerr
Founder, Mobile Toolworks
robkerr@mobiletoolworks.com
2. copyright (c) 2015 Mobile Toolworks, LLC
About Me
Rob is the founder of Mobile Toolworks, where he helps
startup and established companies reinvent their businesses
using cloud-enabled mobile technologies.
Rob became an entrepreneur early on, starting a custom
software business while in college. Subsequently he played
instrumental roles helping build a series of successful
technology companies.
He received a degree in Computer Information Systems from
Western Michigan University, holds patents in connected
device sensor analysis, was awarded Microsoft’s Most
Valued Professional (MVP) for his tech community
contributions, and held software engineering, consulting and
executive-level management positions prior to founding
Mobile Toolworks. Robert Kerr
Founder, Mobile Toolworks
robkerr@mobiletoolworks.com
3. copyright (c) 2015 Mobile Toolworks, LLC
Agenda
Begin with a demo!
Bluetooth Intro for Application Developers
Core Bluetooth Development: Centrals and Peripherals
Application Architecture
Real-world Example : a custom peripheral in Swift (iPhone/Apple
Watch)
What makes an iBeacon an iBeacon?
Using your iBeacon vendor’s API rather than Core Bluetooth
Real-world Example : using iBeacons to enhance the customer
experiences (iPhone)
5. copyright (c) 2015 Mobile Toolworks, LLC
Demo #1 – iBeacon Proximity
Food
Images
iBeacon
Location
& Analytics
iPhone 6
Pool Area
Restaurant
Bar
3m
15m
25m
6. copyright (c) 2015 Mobile Toolworks, LLC
Demo #2 – Controlling BLE Firmware
with an iPhone
Red Bear BT Module
(Nordic Semi Chip)
“Robot” is “running”
when light is green
Light Sensor
Temperature
Sensor
BLE GATT
7. copyright (c) 2015 Mobile Toolworks, LLC
Demo #3 – Controlling BLE Firmware
with an Apple Watch Extension
BT Pairing
BLE GATT
9. copyright (c) 2015 Mobile Toolworks, LLC
Wireless for Peripherals – c.1996
Business-RF
MC-Link
Low Power RF
I explained that Bluetooth was borrowed from the 10th century, second
King of Denmark, King Harald Bluetooth; who was famous for uniting
Scandinavia just as we intended to unite the PC and cellular industries
with a short-range wireless link.
-- Jim Kardach, Intel
http://www.eetimes.com/document.asp?doc_id=1269737
10. copyright (c) 2015 Mobile Toolworks, LLC
Bluetooth Evolution
1.0
Bugs &
Problems
Bug Fixes
1.1
721 kbit/s
Freq
Hopping
1.2
2000 2002 2005
2.0 2.1 3.0
2004 2007 2009
3 mbit/s
EDR
Secure
Simple
Pairing
24 mbit/s
(802.11)
Remember Pairing by Entering “0000”?
4.0 4.1 4.2
2010 2013 2014
BLE Stack
Co-
Existence
IoT
Features
BLE Stack can connect without pairing
“Just Works” (user confirms OK) or Out-of-band Paring (NFC chip, etc.)
iOS 5.0 Core Bluetooth
(BLE Feature Stack)
This is where it
gets interesting
iOS 7.0 Core BT
Revised
(Yay!)
12. copyright (c) 2015 Mobile Toolworks, LLC
Centrals & Peripherals
Central
(a/k/a/ “Client”)
iPhone/iPad
Proximity
Beacon
Raspberry Pi + BT Module
Heart Monitor
Environmental Sensor
Peripheral
(a/k/a/ “Server”)
13. copyright (c) 2015 Mobile Toolworks, LLC
Centrals communicate with Peripherals
using UUIDs
Peripheral
Service
713D0000-503E-4C75-BA94-3148F18D941E
Characteristic 1
713D0000-4001-4C75-BA94-3148F18D941E
713D0000-4002-4C75-BA94-3148F18D941E
Characteristic 2
Characteristic n
.
.
9FE4 4D29
UUID Mfg Data (optional)
nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
peripheral
broadcasts its
service info
Central
connects to
peripheral
to interact with
characteristics
14. copyright (c) 2015 Mobile Toolworks, LLC
Using Core Bluetooth APIs
CBCentralManager
func scanForPeripheralsWithServices(..)
func stopScan()
func connectPeripheral(..)
func cancelPeripheralConnection(..)
CBPeripheral
func discoverServices(..)
func discoverCharacteristics(..)
func writeValueForCharacteristic(..)
MyAppObject : CBPeripheralDelegate
func DidDiscoverServices(..)
func
DidDiscoverCharacteristicsForService(..)
func DidUpdateValueForCharacteristic(..)
func DidUpdateValueForCharacteristic(..)
MyAppObject : CBCentralManagerDelegate
fund DidUpdateState(..)
func DidDiscoverPeripheral()
func DidConnectPeripheral
func DidFailToConnectPeripheral(..)
func DidDisconnectPeripheral(..)
Core Bluetooth API Your Objects
Central
Ops
Peripheral
Ops
15. copyright (c) 2015 Mobile Toolworks, LLC
Typical Peripheral Interop Process
scanForPeripheralsWithServic
e
didDiscoverPeripheral
connectPeripheral
didConnectPeripheral
discoverServices
didDiscoverServices
discoverCharacteristicsForService
didDiscoverCharacteristicsForService
writeValueForCharacteristic...)
didWriteValueForCharacteristic
didUpdateValueForCharacteristic
readValueforCharacteristic(..)
didUpdateValueForCharacteristic
cancelPeripheralConnection
17. copyright (c) 2015 Mobile Toolworks, LLC
Pattern for app with only foreground
scanning
BTDiscoveryService
:
CBCentralManagerDelegate
BTPeripheralService
:
CBPeripheralDelegate
AppDelegate
ViewController
: BTDiscoveryServiceDelegate,
BTPeripheralServiceDelegate
Notify VC
of BT events
Discovery service
is factory for connected
peripheral objects
18. copyright (c) 2015 Mobile Toolworks, LLC
Pattern for app with background
scanning
BTDiscoveryService
:
CBCentralManagerDelegate
BTPeripheralService
: CBPeripheralDelegate
AppDelegate
: BTDiscoveryServiceDelegate
(Singleton in global scope)
ViewController
: BTDiscoveryServiceDelegate,
BTPeripheralServiceDelegate
Notify delegates
of BT events Discovery service
is factory for connected
peripheral objects
19. copyright (c) 2015 Mobile Toolworks, LLC
Things to know about
Your app can scan on-demand, or scan at all times in the background
Scanning can continue even when the device is in standby
In this case, iOS throttles down some features to conserve battery
Core Bluetooth launches your app when BLE services of interest to it are
observed
Being in “scanning mode” does consume battery, but with BLE mode not
very much (see next slide)
Still, don’t scan when you don’t need to – you’re wasting battery life with no
value provided to the user
Stay connected to a peripheral for as short a duration as possible
Only one Central can be connected at the same time. Connect, interop, and
disconnect
If developing your own firmware, use the “manufacturer data” in the
advertising frame to avoid the need for Central apps to connect at all.
20. copyright (c) 2015 Mobile Toolworks, LLC
Battery drain when scanning
http://www.aislelabs.com/reports/ibeacon-battery-drain-iphones/
23. copyright (c) 2015 Mobile Toolworks, LLC
iBeacons from various manufacturers
Estimote
Gimbal
Red Bear
PassKit
BlueCats
Roximity
Kontact.io
Radius
Beacon
BlueUp
24. copyright (c) 2015 Mobile Toolworks, LLC
Inside an iBeacon
http://beekn.net/2013/11/whats-inside-an-estimote/
25. copyright (c) 2015 Mobile Toolworks, LLC
Inside an iBeacon
Nordic Semi SoC
(32-bit ARM Coretex CPU with
Bluetooth LE Radio)
Antenna
Accelerometer
26. copyright (c) 2015 Mobile Toolworks, LLC
What is an iBeacon?
iBeacon is just a specification for a peripheral
The advertisement frame identifies a beacon, and provides enough
information to enable a proximity application
713D0000-503E-4C75-BA94-3148F18D941E 9FE4
UUID MajorCompany ID
4C00
Data Type
02
Data Length
21
Minor
4D29
Power@1
M
5C
☞
Some beacons go further, providing temperature, accelerometer, and
enhancements
Use the Beacon vendor’s SDK to access extensions
27. copyright (c) 2015 Mobile Toolworks, LLC
Do I use Core Bluetooth or the vendor
SDK?
If the beacon follows iBeacon, then you should be able to use Core
Bluetooth vanilla.
Or you can use the SDK provided by your iBeacon vendor if one is
provided
Can be an abstraction layer over Core Bluetooth
Less coding for you (?)
But maybe less control as well
The SDK provides access to extensions not necessarily part of the iBeacon
specification
Some vendors include cloud-based analytics and opportunities to use other
beacons and/or “rent” the use of your beacons to others (especially Gimbal)
The vendor SDK is almost certainly necessary to leverage these value-
added capabilities
28. copyright (c) 2015 Mobile Toolworks, LLC
Analytics when using Estimote SDK
with Estimote iBeacons