building a mobile location aware system with beacons

49
Tim Messerschmidt Head of Developer Relations, International Braintree_PayPal @Braintree_Dev / @SeraAndroid Building a Mobile Location Aware System with Beacons #OSCON

Upload: tim-messerschmidt

Post on 16-Apr-2017

1.293 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Building a Mobile Location Aware System with Beacons

Tim Messerschmidt Head of Developer Relations, International

Braintree_PayPal

@Braintree_Dev / @SeraAndroid

Building a Mobile Location Aware System with Beacons

#OSCON

Page 2: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

A Beacon’s Purpose

Page 3: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Location Awareness

Page 4: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Source: http://communityhealthmaps.nlm.nih.gov/2014/07/07/how-accurate-is-the-gps-on-my-smart-phone-part-2

GPS 3m

A-GPS 8m

WiFi 75m

Cellular 600m

Leveraging Your Phone’s Hardware

Page 5: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

GPS vs Bluetooth Smart

Page 6: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Bluetooth vs Bluetooth Smart

Page 7: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Triangulation

Beacon

Beacon

Beacon

PositionMeasuring Angles From a Fixed Location

Page 8: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Trilateration

Beacon

BeaconBeacon

PositionMeasuring Distances From a Fixed Location

Page 9: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Applying This to the real world

Page 10: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Page 11: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Behind the Magic

Beacon Device

Advertisement

Page 12: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Behind the Magic

Beacon Device Endpoint

Page 13: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Popular Beacon Choices

Estimote 99 $ / 3

Gimbal 5 $

Bluecats 29 $

Kontakt.io 81 $ / 3

Page 14: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Advertising Beacons

UUID (16 Bytes): Large Beacon Group Major (2 Bytes): The Beacon Subset Minor (2 Bytes): The individual Beacon Tx Power: translates into distance

Page 15: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Avoid Being creepy

Page 16: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Deploying Beacons

Page 17: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Range vs. Battery

Page 18: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Page 19: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Replacing Batteries

Page 20: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

SiGnal Interference

Page 21: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Confounding Factors

Microwave ovens Direct Satellite Services External electrical Sources Monitors and LCD Displays Anything that uses 2.4 or 5 GHz

Page 22: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

SiGnal degradation

Page 23: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

reddit.com/r/gifs/comments/2qv6xv/visualization_of_wifi_signal_strength_in_a_room

Page 24: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Low Interference

Wood Glass Synthetic Material

Medium Interference

Water Bricks Marble

Very High Interference

Metal

High Interference

Plaster Concrete bulletproof Glass

Page 25: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Attaching to a Beacon

Page 26: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

dependencies { compile 'com.estimote:sdk:0.9.1@aar' }

Resolving The Dependency

Source: http://github.com/Estimote/Android-SDK

Page 27: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

getMacAddress() getMajor() getMinor() getMeasuredPower()

The Estimote Beacon Object

Source: http://estimote.github.io/Android-SDK/JavaDocs/com/estimote/sdk/Beacon.html

getName() getProximityUUID() getRssi()

Page 28: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

public class BeaconApplication extends Application { private static final String ESTIMOTE_APP_ID = "FROM THE ESTIMOTE CLOUD"; private static final String ESTIMOTE_APP_TOKEN = "FROM THE ESTIMOTE CLOUD"; @Override public void onCreate() { super.onCreate(); EstimoteSDK.initialize(this, ESTIMOTE_APP_ID, ESTIMOTE_APP_TOKEN); EstimoteSDK.enableDebugLogging(true); } }

Initializing the SDK

Page 29: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

public class BeaconApplication extends Application implements BeaconManager.ServiceReadyCallback { private static final String ESTIMOTE_APP_ID = "FROM THE ESTIMOTE CLOUD"; private static final String ESTIMOTE_APP_TOKEN = "FROM THE ESTIMOTE CLOUD"; private BeaconManager beaconManager; @Override public void onCreate() { super.onCreate(); … beaconManager = new BeaconManager(this); beaconManager.connect(this); } @Override public void onServiceReady() { final Region regionOne = new Region("First region", UUID.fromString("Beacon UUID"), 22504, 44870); beaconManager.startMonitoring(regionOne); } }

Monitoring a Single Beacon

Page 30: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

public class BeaconApplication extends Application implements BeaconManager.ServiceReadyCallback { private static final String ESTIMOTE_APP_ID = "FROM THE ESTIMOTE CLOUD"; private static final String ESTIMOTE_APP_TOKEN = "FROM THE ESTIMOTE CLOUD"; private BeaconManager beaconManager; @Override public void onCreate() { super.onCreate(); … beaconManager = new BeaconManager(this); beaconManager.connect(this); } @Override public void onServiceReady() { final Region regionOne = new Region("First region", UUID.fromString("Beacon UUID"), null, null); beaconManager.startMonitoring(regionOne); } }

Monitoring multiple BeaconS

Page 31: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

public class BeaconApplication extends Application implements BeaconManager.ServiceReadyCallback, BeaconManager.MonitoringListener { @Override public void onServiceReady() { final Region regionOne = new Region("First region", UUID.fromString("Beacon UUID"), null, null); beaconManager.startMonitoring(regionOne); } @Override public void onEnteredRegion(Region region, List<Beacon> list) { // Interact with the region final String regionId = region.getIdentifier(); … } @Override public void onExitedRegion(Region region) { // Notify the user that he left the region } }

Interacting with Regions

Page 32: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

public class BeaconApplication extends Application implements BeaconManager.ServiceReadyCallback, BeaconManager.RangingListener { private static final String ESTIMOTE_APP_ID = "FROM THE ESTIMOTE CLOUD"; private static final String ESTIMOTE_APP_TOKEN = "FROM THE ESTIMOTE CLOUD"; private BeaconManager beaconManager; @Override public void onServiceReady() { final Region regionOne = new Region("First region", UUID.fromString("Beacon UUID"), null, null); beaconManager.startRanging(regionOne); } @Override public void onBeaconsDiscovered(Region region, List<Beacon> list) { final Beacon closestBeacon = list.get(0); // Interact with the beacon } }

Ranging Beacons

Page 33: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

public class BeaconApplication extends Application implements BeaconConnection.ConnectionCallback, BeaconConnection.WriteCallback { private void configureBeacon(Beacon beacon) { final BeaconConnection connection = new BeaconConnection(this, beacon, this); connection.authenticate(); connection.edit() .set(connection.major(), 11) .set(connection.minor(), 3) .commit(this); connection.close(); }

// Implement the two interfaces for successful authentication and writing the configuration …}

Configuring Beacons

Page 34: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid

Distance vs Signal Strength

Source: http://developer.estimote.com/android/tutorial/part-3-ranging-beacons

0

25

50

75

100

1m 2m 4m 8m

Page 35: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Important: While received signal strength, proximity zone and accuracy values can theoretically be used to derive a distance estimation, in practice this is far from trivial and requires complex mathematical models to account for fluctuations in the signal strength.

Long story short: do not expect distance estimations from beacons.

Measuring Distance

Source: http://developer.estimote.com/android/tutorial/part-3-ranging-beacons

Page 36: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

immediate (strong signal) near (medium signal) far (weak signal) unknown (very weak signal)

Measuring Distance

Source: http://developer.estimote.com/android/tutorial/part-3-ranging-beacons

Page 37: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

immediate (strong signal) - NFC near (medium signal) - Beacons far (weak signal) - Beacons unknown (very weak signal)

Measuring Distance

Source: http://developer.estimote.com/android/tutorial/part-3-ranging-beacons

Page 38: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

computeAccuracy() computeProximity() isBeaconInRegion() proximityFromAccuracy()

The Utils Class

Source: http://estimote.github.io/Android-SDK/JavaDocs/com/estimote/sdk/Utils.html

Page 39: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Ranging vs Monitoring

Page 40: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Page 41: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Page 42: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Page 43: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Page 44: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Testing BLE on Android

Page 45: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

BLE & Android’s Emulator

Virtual Machine + USB BLE Adapter chrislarson.me/blog/emulate-android-and-bluetooth-le-hardware.html

Page 46: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Altbeacon

Page 47: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

Eddystone vs iBeacon

Page 48: Building a Mobile Location Aware System with Beacons

@Braintree_Dev / @SeraAndroid#OSCON

reference Material

Beacon vs BLE: link-labs.com/bluetooth-vs-bluetooth-low-energy ALTBEACON: altbeacon.org iBeacon Specification: developer.apple.com/ibeacon Estimote JavaDoc: estimote.github.io/Android-SDK/JavaDocs Eddystone: github.com/google/eddystone

Page 49: Building a Mobile Location Aware System with Beacons

@SeraAndroid [email protected]

slideshare.net/paypal braintreepayments.com/developers

Thank you!