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

How Hot is My Coffee? Sensors, Core Bluetooth, and Swift!

Embed Size (px)

Citation preview

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

How Hot is My Coffee? Sensors, Core Bluetooth, and Swi8!

Evan K. Stone Senior iOS Developer

Cloud City Development // San Francisco

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

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

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

There is an explosion.

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

Not bombs.

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

Usually doesn’t hurt people.

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

Very o8en helps people.

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

This explosion is…

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

The Internet of Things

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

Connected devices

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

Nest. Fitbit. Polar.

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

Key technology behind it?

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

Bluetooth Low Energy

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

What is it?

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

Not Classic Bluetooth.

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

A lightweight subset

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

AKA “Bluetooth Smart”

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

Why do we care?

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

It’s exciSng!

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

It’s fun!

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

It can be rewarding.

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

Allows us to interact with physical devices

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

We can develop iOS apps that communicate with other things

around us!

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

No cerSficaSon required!

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

Super Low Barrier for Entry.

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

TI SensorTag Ambient Light

Digital Microphone

MagneSc Sensor

Humidity

Accelerometer GyroscopeMagnetometer

Ambient Temperature

IR Temperature

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

$29

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

What does this mean for us?

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

The IoT Landscape is changing

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

Tons of innovaSon going on right now.

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

Startups

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

Incubators and Accelerators

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

They will need you.

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

Ge]ng started now will help you help them.

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

Side note:

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

What about iBeacons?

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

Subject of another talk!

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

iBeacons are BLE devices.

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

Behave differently

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

They are also fun to work with.

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

Are handled by a different framework!

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

Core LocaSon

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

Ge]ng back to BLE…

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

Acronym Time!

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

GAPGeneric Access Profile

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

Defines how devices adver&se themselves and how they connect

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

Defines the concept of the Central and the Peripheral

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

GATTGeneric Aaribute Profile

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

Defines the way devices transfer data back and forth

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

Introduces Services and CharacterisScs

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

You won’t be tested on the acronyms.

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

Just know they exist.

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

Roles

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

We are already used to Client and Server roles

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

In BLE we have the Central and Peripheral roles

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

Central

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

Wants data from a Peripheral

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

Generally this is your iOS device.

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

Peripheral

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

Supplies data.

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

A device like a heart rate monitor

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

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

have previously

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

Side note:

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

An iOS device can be a Peripheral…

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

…but typically they act as a Central.

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

The Age of Discovery

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

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

other.

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

AdverSsing and Discovery

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

The Peripheral AdverSses

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

The Central scans and listens

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

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

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

Kinda like a headhunter on LinkedIn.

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

Services and CharacterisScs

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

Services group data

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

Services contain CharacterisScs

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

Service

Characteris2c

Characteris2c

Characteris2c

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

Central connects and discovers Services and CharacterisScs the

peripheral offers

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

But how?

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

Core Bluetooth

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

Apple’s abstracSon over all that Bluetooth gobbledygook.

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

Encapsulates the funcSonality of the BLE enSSes in framework classes

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

Remember the four main players?

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

Central and Peripheral. Service and CharacterisSc.

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

Everything begins with a CB

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

Peripheral

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

CBPeripheral

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

Central

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

CBCentralManager

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

Service

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

CBService

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

CharacterisSc

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

CBCharacterisSc

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

Side note:

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

Caveat with Core Bluetooth development

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

iOS Simulator does not support BLE.

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

So you have to use a device.

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

Which devices support BLE?

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

iPhone 4s and later.iPad 3 and later.

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

Basic Workflow

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

Feels very client-server

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

That’s not an accident.

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

Workflow:

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

InstanSate a CBCentralManager

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

Tell CBCentralManager to scan for Peripherals with Services

we want

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

When it finds a Peripheral, request to connect

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

A8er connecSng, find out more about the Peripheral

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

Read and set characterisScs

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

Rinse, Lather, Repeat…

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

Disconnect.

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

What makes this work?

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

Enter the UUID.

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

Enter the UUID.

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

Standard UUIDs have a 16-bit form.

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

0x180A

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

Custom UUIDs have a 128-bit form.

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

F000AA00-0451-4000-B000-000000000000

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

What do we mean by Standard and Custom UUIDs?

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

For example…

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

Heart Rate Monitor Service0x180D

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

Heart Rate Measurement CharacterisSc

0x2A37

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

ExciSng Reading!developer.bluetooth.org

🤓

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

Custom Service UUIDs

Anything not listed on the standard list.

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

For example…

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

IR Temperature SensorF000AA00-0451-4000-B000-000000000000

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

Where do I find these crazy numbers?

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

Typically on the vendor website

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

Or the hardware engineer on your team creates them!

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

Back to scanning…

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

CBCentralManager

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

Core Bluetooth relies heavily on delegates

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

CBCentralManagerDelegate

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

CBPeripheralDelegate

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

Demo Time!

🎉

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

How Hot is My Coffee?

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

Side note:

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

Backgrounding

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

Yes it’s possible!

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

Requires a flag in your Info.plist

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

key: UIBackgroundModesvalue: bluetooth-central

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

Devices

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

Many to choose from

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

New ones appear constantly

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

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

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

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

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

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

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

TinyCircuitshaps://Sny-circuits.com/

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

The IoT space is exploding!

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

More connected devices are being developed every day!

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

More connected apps are needed every day!

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

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

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

Explore!

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

Experiment!

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

Connect and Communicate

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

Core Bluetooth.

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

Resources

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

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, Core Bluetooth, and Swift!

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

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

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