Use Bluetooth to connect your iOS app to the Internet of Things
-
Upload
robert-kerr -
Category
Software
-
view
261 -
download
0
Transcript of Use Bluetooth to connect your iOS app to the Internet of Things
Using Bluetooth to connect your iOS app to The Internet
of Things
Robert KerrFounder, Mobile [email protected]
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 KerrFounder, Mobile [email protected]
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)
Begin with a demo!
copyright (c) 2015 Mobile Toolworks, LLC
Demo #1 – iBeacon Proximity
Food Images
iBeacon Location
& Analytics
iPhone 6Pool Area
RestaurantBar
3m
15m
25m
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
copyright (c) 2015 Mobile Toolworks, LLC
Demo #3 – Controlling BLE Firmware with an Apple Watch Extension
BT PairingBLE GATT
Bluetooth Intro for Application Developers
copyright (c) 2015 Mobile Toolworks, LLC
Wireless for Peripherals – c.1996
Business-RF
MC-LinkLow 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
copyright (c) 2015 Mobile Toolworks, LLC
Bluetooth Evolution
1.0
Vers
ion
Know
n fo
r
Bugs & Problems
Bug Fixes
1.1
721 kbit/sFreq
Hopping
1.2
2000 2002 2005
2.0 2.1 3.0
2004 2007 2009
3 mbit/sEDR
Secure Simple Pairing
24 mbit/s(802.11)
Year
Remember Pairing by Entering “0000”?
4.0 4.1 4.2
2010 2013 2014
BLE StackCo-
ExistenceIoT
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!)
Core Bluetooth Development:
Centrals & Peripherals
copyright (c) 2015 Mobile Toolworks, LLC
Centrals & PeripheralsCentral
(a/k/a/ “Client”)
iPhone/iPad
Proximity Beacon
Raspberry Pi + BT Module
Heart Monitor
Environmental Sensor
Peripheral(a/k/a/ “Server”)
copyright (c) 2015 Mobile Toolworks, LLC
Centrals communicate with Peripherals using UUIDs
PeripheralService
713D0000-503E-4C75-BA94-3148F18D941E
Characteristic 1 713D0000-4001-4C75-BA94-3148F18D941E
713D0000-4002-4C75-BA94-3148F18D941E
Characteristic 2
Characteristic n
.
.
9FE4 4D29
UUIDMfg Data (optional)
nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
peripheralbroadcasts its service
info
Centralconnects toperipheralto interact
withcharacteristics
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
Centr
al
Ops
Peri
phera
lO
ps
copyright (c) 2015 Mobile Toolworks, LLC
Typical Peripheral Interop ProcessscanForPeripheralsWithSer
vice
didDiscoverPeripheral
connectPeripheral
didConnectPeripheral
discoverServices
didDiscoverServices
discoverCharacteristicsForService
didDiscoverCharacteristicsForService
writeValueForCharacteristic...)
didWriteValueForCharacteristic
didUpdateValueForCharacteristic
readValueforCharacteristic(..)
didUpdateValueForCharacteristic
cancelPeripheralConnection
Application Architecture
copyright (c) 2015 Mobile Toolworks, LLC
Pattern for app with only foreground scanning
BTDiscoveryService : CBCentralManagerDelegate
BTPeripheralService : CBPeripheralDelegate
AppDelegate
ViewController : BTDiscoveryServiceDelegate, BTPeripheralServiceDelegate
Notify VCof BT events
Discovery service is factory for connected peripheral objects
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 delegatesof BT events Discovery service
is factory for connected peripheral objects
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.
copyright (c) 2015 Mobile Toolworks, LLC
Battery drain when scanninghttp://www.aislelabs.com/reports/ibeacon-battery-drain-iphones/
Code ReviewControlling a custom firmware peripheral
using Swift on iPhone & Apple Watch
What makes an iBeacon an iBeacon?
copyright (c) 2015 Mobile Toolworks, LLC
iBeacons from various manufacturers
EstimoteGimbal
Red Bear
PassKit
BlueCats
Roximity
Kontact.io
Radius Beacon
BlueUp
copyright (c) 2015 Mobile Toolworks, LLC
Inside an iBeacon
http://beekn.net/2013/11/whats-inside-an-estimote/
copyright (c) 2015 Mobile Toolworks, LLC
Inside an iBeacon
Nordic Semi SoC(32-bit ARM Coretex CPU with
Bluetooth LE Radio)
Antenna
Accelerometer
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 Major
Company ID
4C00
Data Type
02
Data Length
21
Minor
4D29
Power@1M
5C
Apple
iBeaco
n CountUUID
Regio
n Beaco
n
#
Used
to ca
lcula
te
dist
ance
from
the
beac
on☞
Some beacons go further, providing temperature, accelerometer, and enhancements Use the Beacon vendor’s SDK to access extensions
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
copyright (c) 2015 Mobile Toolworks, LLC
Analytics when using Estimote SDK with Estimote iBeacons
Code ReviewUsing iBeacons to enhance
the customer experiences (iPhone)
Questions?