Use Bluetooth to connect your iOS app to the Internet of Things

30
Using Bluetooth to connect your iOS app to The Internet of Things Robert Kerr Founder, Mobile Toolworks robkerr@mobiletoolworks .com

Transcript of Use Bluetooth to connect your iOS app to the Internet of Things

Page 1: 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]

Page 2: Use Bluetooth to connect your iOS app to the Internet of Things

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]

Page 3: Use Bluetooth to connect your iOS app to the Internet of Things

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)

Page 4: Use Bluetooth to connect your iOS app to the Internet of Things

Begin with a demo!

Page 5: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

Demo #1 – iBeacon Proximity

Food Images

iBeacon Location

& Analytics

iPhone 6Pool Area

RestaurantBar

3m

15m

25m

Page 6: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 7: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

Demo #3 – Controlling BLE Firmware with an Apple Watch Extension

BT PairingBLE GATT

Page 8: Use Bluetooth to connect your iOS app to the Internet of Things

Bluetooth Intro for Application Developers

Page 9: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 10: Use Bluetooth to connect your iOS app to the Internet of Things

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!)

Page 11: Use Bluetooth to connect your iOS app to the Internet of Things

Core Bluetooth Development:

Centrals & Peripherals

Page 12: Use Bluetooth to connect your iOS app to the Internet of Things

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”)

Page 13: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 14: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 15: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

Typical Peripheral Interop ProcessscanForPeripheralsWithSer

vice

didDiscoverPeripheral

connectPeripheral

didConnectPeripheral

discoverServices

didDiscoverServices

discoverCharacteristicsForService

didDiscoverCharacteristicsForService

writeValueForCharacteristic...)

didWriteValueForCharacteristic

didUpdateValueForCharacteristic

readValueforCharacteristic(..)

didUpdateValueForCharacteristic

cancelPeripheralConnection

Page 16: Use Bluetooth to connect your iOS app to the Internet of Things

Application Architecture

Page 17: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 18: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 19: Use Bluetooth to connect your iOS app to the Internet of Things

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.

Page 20: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

Battery drain when scanninghttp://www.aislelabs.com/reports/ibeacon-battery-drain-iphones/

Page 21: Use Bluetooth to connect your iOS app to the Internet of Things

Code ReviewControlling a custom firmware peripheral

using Swift on iPhone & Apple Watch

Page 22: Use Bluetooth to connect your iOS app to the Internet of Things

What makes an iBeacon an iBeacon?

Page 23: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

iBeacons from various manufacturers

EstimoteGimbal

Red Bear

PassKit

BlueCats

Roximity

Kontact.io

Radius Beacon

BlueUp

Page 24: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

Inside an iBeacon

http://beekn.net/2013/11/whats-inside-an-estimote/

Page 25: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

Inside an iBeacon

Nordic Semi SoC(32-bit ARM Coretex CPU with

Bluetooth LE Radio)

Antenna

Accelerometer

Page 26: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 27: Use Bluetooth to connect your iOS app to the Internet of Things

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

Page 28: Use Bluetooth to connect your iOS app to the Internet of Things

copyright (c) 2015 Mobile Toolworks, LLC

Analytics when using Estimote SDK with Estimote iBeacons

Page 29: Use Bluetooth to connect your iOS app to the Internet of Things

Code ReviewUsing iBeacons to enhance

the customer experiences (iPhone)

Page 30: Use Bluetooth to connect your iOS app to the Internet of Things

Questions?