how hot is my coffee? sensors, ios and core bluetooth

163
How Hot is My Coffee? Sensors, iOS and Core Bluetooth Evan K. Stone Senior iOS Developer Cloud City Development // San Francisco

Upload: evan-stone

Post on 17-Feb-2017

187 views

Category:

Devices & Hardware


3 download

TRANSCRIPT

Page 1: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Evan K. Stone Senior iOS Developer

Cloud City Development // San Francisco

Page 2: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

An integrated design and so-ware consultancy specializing in web and mobile apps

Page 3: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

There is an explosion.

Page 4: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Not bombs.

Page 5: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Usually doesn’t hurt people.

Page 6: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Very oCen helps people.

Page 7: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

This explosion is…

Page 8: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

The Internet of Things

Page 9: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Connected devices

Page 10: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Nest. Fitbit. Polar.

Page 11: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Key technology behind it?

Page 12: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Bluetooth Low Energy

Page 13: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

What is it?

Page 14: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Not Classic Bluetooth.

Page 15: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

A lightweight subset

Page 16: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

AKA “Bluetooth Smart”

Page 17: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Why do we care?

Page 18: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

It’s exciSng!

Page 19: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

It’s fun!

Page 20: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

It can be rewarding.

Page 21: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Allows us to interact with physical devices

Page 22: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

We can develop iOS apps that communicate with other things

around us!

Page 23: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

No cerSficaSon required!

Page 24: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Super Low Barrier for Entry.

Page 25: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

TI SensorTag Ambient Light

Digital Microphone

MagneSc Sensor

Humidity

Accelerometer GyroscopeMagnetometer

Ambient Temperature

IR Temperature

Page 26: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

$29

Page 27: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

What does this mean for us?

Page 28: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

The IoT Landscape is changing

Page 29: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Tons of innovaSon going on right now.

Page 30: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Startups

Page 31: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Incubators and Accelerators

Page 32: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

They will need you.

Page 33: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Ge]ng started now will help you help them.

Page 34: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Side note:

Page 35: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

What about iBeacons?

Page 36: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Subject of another talk!

Page 37: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

iBeacons are BLE devices.

Page 38: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Behave differently

Page 39: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

They are also fun to work with.

Page 40: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Are handled by a different framework!

Page 41: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Core LocaSon

Page 42: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Ge]ng back to BLE…

Page 43: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Acronym Time!

Page 44: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

GAPGeneric Access Profile

Page 45: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Defines how devices adver&se themselves and how they connect

Page 46: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Defines the concept of the Central and the Peripheral

Page 47: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

GATTGeneric Aaribute Profile

Page 48: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Defines the way devices transfer data back and forth

Page 49: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Introduces Services and CharacterisScs

Page 50: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

You won’t be tested on the acronyms.

Page 51: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Just know they exist.

Page 52: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Roles

Page 53: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

We are already used to Client and Server roles

Page 54: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

In BLE we have the Central and Peripheral roles

Page 55: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Central

Page 56: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Wants data from a Peripheral

Page 57: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Generally this is your iOS device.

Page 58: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Peripheral

Page 59: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Supplies data.

Page 60: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

A device like a heart rate monitor

Page 61: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Becomes an extension of our iOS device, giving it abiliSes it didn’t

have previously

Page 62: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Side note:

Page 63: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

An iOS device can be a Peripheral…

Page 64: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

…but typically they act as a Central.

Page 65: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

The Age of Discovery

Page 66: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

For devices to communicate with each other, they must find each

other.

Page 67: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

AdverSsing and Discovery

Page 68: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

The Peripheral AdverSses

Page 69: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

The Central scans and listens

Page 70: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

When it finds a Peripheral, the Central can ask to connect.

Page 71: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Kinda like a headhunter on LinkedIn.

Page 72: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Services and CharacterisScs

Page 73: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Services group data

Page 74: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Services contain CharacterisScs

Page 75: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Service

Characteris2c

Characteris2c

Characteris2c

Page 76: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Central connects and discovers Services and CharacterisScs the

peripheral offers

Page 77: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

But how?

Page 78: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Core Bluetooth

Page 79: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Apple’s abstracSon over all that Bluetooth gobbledygook.

Page 80: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Encapsulates the funcSonality of the BLE enSSes in framework classes

Page 81: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Remember the four main players?

Page 82: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Central and Peripheral. Service and CharacterisSc.

Page 83: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Everything begins with a CB

Page 84: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Peripheral

Page 85: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CBPeripheral

Page 86: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Central

Page 87: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CBCentralManager

Page 88: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Service

Page 89: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CBService

Page 90: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CharacterisSc

Page 91: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CBCharacterisSc

Page 92: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Side note:

Page 93: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Caveat with Core Bluetooth development

Page 94: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

iOS Simulator does not support BLE.

Page 95: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

So you have to use a device.

Page 96: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Which devices support BLE?

Page 97: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

iPhone 4s and later.iPad 3 and later.

Page 98: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Basic Workflow

Page 99: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Feels very client-server

Page 100: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

That’s not an accident.

Page 101: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Workflow:

Page 102: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

InstanSate a CBCentralManager

Page 103: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Tell CBCentralManager to scan for Peripherals with Services

we want

Page 104: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

When it finds a Peripheral, request to connect

Page 105: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

ACer connecSng, find out more about the Peripheral

Page 106: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Read and set characterisScs

Page 107: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Rinse, Lather, Repeat…

Page 108: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Disconnect.

Page 109: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

What makes this work?

Page 110: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Enter the UUID.

Page 111: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Enter the UUID.

Page 112: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Standard UUIDs have a 16-bit form.

Page 113: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

0x180A

Page 114: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Custom UUIDs have a 128-bit form.

Page 115: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

F000AA00-0451-4000-B000-000000000000

Page 116: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

What do we mean by Standard and Custom UUIDs?

Page 117: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

For example…

Page 118: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Heart Rate Monitor Service0x180D

Page 119: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Heart Rate Measurement CharacterisSc

0x2A37

Page 120: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

ExciSng Reading!developer.bluetooth.org

🤓

Page 121: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Custom Service UUIDs

Anything not listed on the standard list.

Page 122: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

For example…

Page 123: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

IR Temperature SensorF000AA00-0451-4000-B000-000000000000

Page 124: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Where do I find these crazy numbers?

Page 125: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Typically on the vendor website

Page 126: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Or the hardware engineer on your team creates them!

Page 127: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Back to scanning…

Page 128: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CBCentralManager

Page 129: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Core Bluetooth relies heavily on delegates

Page 130: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CBCentralManagerDelegate

Page 131: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

CBPeripheralDelegate

Page 132: How Hot is My Coffee? Sensors, iOS and Core Bluetooth
Page 133: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Demo Time!

🎉

Page 134: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

How Hot is My Coffee?

Page 135: How Hot is My Coffee? Sensors, iOS and Core Bluetooth
Page 136: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Side note:

Page 137: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Backgrounding

Page 138: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Yes it’s possible!

Page 139: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Requires a flag in your Info.plist

Page 140: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

key: UIBackgroundModesvalue: bluetooth-central

Page 141: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Devices

Page 142: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Many to choose from

Page 143: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

New ones appear constantly

Page 144: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

TI SensorTaghap://www.S.com/sensortag

Page 145: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

LightBlue Bean/Bean+haps://punchthrough.com/bean

Page 146: How Hot is My Coffee? Sensors, iOS and Core Bluetooth
Page 147: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Adafruit Feather 32u4 Bluefruit LEhaps://www.adafruit.com/products/2829

Page 148: How Hot is My Coffee? Sensors, iOS and Core Bluetooth
Page 149: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

TinyCircuitshaps://Sny-circuits.com/

Page 150: How Hot is My Coffee? Sensors, iOS and Core Bluetooth
Page 151: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

The IoT space is exploding!

Page 152: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

More connected devices are being developed every day!

Page 153: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

More connected apps are needed every day!

Page 154: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

As an iOS developer, you can be on the cu]ng edge of this new fronSer!

Page 155: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Explore!

Page 156: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Experiment!

Page 157: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Connect and Communicate

Page 158: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Core Bluetooth.

Page 159: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Resources

Page 160: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Cloud City DevelopmentBlog hap://cloudcity.io/blog/2015/06/11/zero-to-ble-on-ios-part-one/ hap://cloudcity.io/blog/2015/10/15/developing-ios-app-using-ble-standard/

GitHub haps://github.com/cloudcity/BLECoffee haps://github.com/cloudcity/ZeroToBLE-Part2

Page 162: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Adafruit's IntroducSon to BLE haps://learn.adafruit.com/introducSon-to-bluetooth-low-energy/introducSon

Page 163: How Hot is My Coffee? Sensors, iOS and Core Bluetooth

Evan K. Stone

web: h<p://www.cloudcity.io

cloud city blog: h<p://blog.cloudcity.io

blog: h<p://www.interac?velogic.net

twi<er: @interac?vlogic