58
Android and BLE: Best Practices and what's new in Android 5.0 google.com/+DarioLaverde HTC Developer Evangelist Thurs, Jan 29, 2015

Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Android and BLE: Best Practices and

what's new in Android 5.0

google.com/+DarioLaverde HTC Developer Evangelist

Thurs, Jan 29, 2015

Page 2: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

First, a developer challenge:

WiFi: HTC_Guest pwd: https://www.htcdev.com/devcenter/opensense-sdk/bluetooth-smart/htc-fetch/ or: http://bit.ly/htcfetch

Page 3: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Android & “The Internet of Things”

connecting to devices from Android: wifi, bluetooth, nfc, … and now BLE and IR BLE API: Bluetooth Low Energy (as of Android 4.3) IR API: Consumer InfraRed (as ofAndroid 4.4!) and the things are getting smaller: stickers, keyfobs, remotes… and wearable: Android Wear, Google Glass….

Page 4: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

IoT (or IoE) - Wearables

Page 5: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

IoT / Wearables: the next big thing

Page 6: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Hype Cycle for Emerging Technologies, 2014

Page 7: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

What is BLE?

●  Started in 2001 - originally introduced under the name Wibree by Nokia in 2006 - merged into the main Bluetooth standard in 2010, when Bluetooth Core Specification Version 4.0 was adopted

●  Low power and improved latency ●  Same radio+antenna so older devices technically could be

retrofitted with the le stack (however requires chipset firmware update)

●  BLE is a part of the Bluetooth 4.1 specification

Page 8: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BT Classic vs BT Low Energy

Page 9: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BT Classic vs BT Low Energy

Page 10: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Bluetooth 4.1 http://developer.bluetooth.org/TechnologyOverview/Pages/v4.aspx

The core spec consists of several parts: ●  Classic Bluetooth technology ●  Bluetooth low energy technology ●  Bluetooth high speed technology

Page 11: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Bluetooth SMART

2011 BT Smart branding:

●  Bluetooth SMART (LE only) ●  Bluetooth SMART Ready (dual mode support)

Page 12: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Bluetooth LE Use Cases Initially we’re seeing Health & Wellness / Sport & Fitness and Proximity use cases – but there’s many more possibilities…

Page 13: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Profiles BLE Profiles: optional specifications for particular set of applications – since they are optional you can create custom ones. http://developer.bluetooth.org/TechnologyOverview/Pages/Profiles.aspx#GATT

Page 14: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Profiles BLE device manufacturers are encouraged by the Bluetooth SIG to build new profiles and even extend current ones with additional “proprietary” characteristics and services. Creates difficulty debugging certain devices for 3rd party app developers without contacting device OEM or reverse engineering.

Page 15: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE and Android Prior to Android 4.3, several OEMs already have devices on the market that support BLE and each provide their own BLE API. HTC, Samsung, Motorola and others

In most if not all cases, you will build on top of the GATT profile – i.e. your app must include the implementation of your required BLE profile(s) - similar to IOS.

Page 16: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Profiles are on top of GATT | V

Page 17: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Protocols BLE GATT Clients and Servers: Servers expose attributes Clients use attributes Client Actions: Discover, Read, Write, Confirm an Indication Server Actions: respond to Client actions, send Notifications

Page 18: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Protocols

Phone (Master – Central Role) Gatt Client

BLE Smart device (Slave – Peripheral Role) Gatt Server

Service Characteristic: value descriptor(s) Observer Role

Page 19: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Protocols Phone (Master – Central Role) Gatt Client

*Phone (Slave – Peripheral Role) Gatt Server

Service

*New support in Android 5.0 (Lollipop)

Characteristic: value descriptor(s) Observer Role

Broadcaster Role

Page 20: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

a small sampling of crowd-sourced BLE startups

cookoo http://www.kickstarter.com/projects/cuckoo/cookootm-the-watch-for-the-connected-generation

StickNFind http://www.indiegogo.com/projects/sticknfind-bluetooth-powered-ultra-small-location-stickers atomwear https://www.kickstarter.com/projects/343910040/atomwear

Page 21: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

now some BLE devices to demo

Page 22: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

HTC Fetch

Page 23: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

HTC Fetch on the Play Store

Page 24: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

HTC Fetch Open BLE Specs From htcdev.com: BLE Profiles: Find Me Profile, Proximity Profile, Battery Service The only addition HTC has added to the standard BLE profiles and service listed above is the following additional service: Service uuid: 0daa5375-02d3-4b47-b6b7-53408ff159e5 Characteristic (Notify) uuid: 1daa5375-02d3-4b47-b6b7-53408ff159e5 This is the service used to enable the "find my phone" feature of HTC Fetch, the characteristic notification sent when the tag's button is pressed.

Page 25: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

RE camera

Page 26: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

RE camera ● BLE + WIFI Direct

●  BLE

control, connection management ●  WIFI

media, streaming

●  APIs forthcoming

Page 27: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Thalmic Lab’s Myo a BLE gesture controlled armband

Page 28: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Kwikset Kevo

Page 29: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Kwikset Kevo

Page 30: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE developer device kits BLE chipset OEMs provide device kits – supporting different profiles The TI SensorTag kit (BLE chipset CC2541) contains 6 sensors and won the best developer kit award of the year by EE Times / EDN Ace Awards. Considered best value for a BLE dev kit at only $25

Page 31: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

TI SensorTag http://ti.com/ble

Page 32: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

TI SensorTag

Page 33: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Bluetooth SIG Developer Portal

http://developer.bluetooth.org

Specifications, sample code, developer resources, videos of webinars and much more…

Page 34: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Beacon support pre-5.0 and 5.0

pre-5.0 (demo with Google Glass) https://github.com/RadiusNetworks/android-ibeacon-service pre-5.0 and 5.0 https://github.com/AltBeacon https://github.com/AltBeacon/android-beacon-library/blob/android-l-apis/src/

main/java/org/altbeacon/beacon/BeaconTransmitter.java

Page 35: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE overview source: https://developer.android.com/guide/topics/connectivity/bluetooth-le.html Setup BLE:

Page 36: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Scanning

Page 37: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Connect to a Gatt Server

note: when autoconnecting First connect directly initially (false) and on disconnect then connect with autoconnect = true

Page 38: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

service discovery, callbacks

Page 39: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

reading characteristics In this case for every service

Page 40: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Receiving Gatt Notifications

Page 41: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Running as a Gatt Server

from BluetoothManager: see api docs for BluetoothGattServer (next slide)

Page 42: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market
Page 43: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

And don’t forget to close!

Page 44: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Sample Code Demo BluetoothLeGatt official Android BLE sample project: BluetoothLeGattExtend adds more services, use cases (work in progress) AltBeacon/android-beacon-library open source Android 5 supported library

Page 45: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE demos BLE demos based on sample code from: - Android SDK - developer.bluetooth.org - Ti.com/ble - bit.ly/htcfetch

Page 46: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Android 5.0 A diff shows about 140+ APIs in the new BLE package alone Most important feature: Peripheral Mode Support! - BLE clients and servers with phones - Phones as devices that run Central Mode Broadcaster (advertising) and Observer (scanning) Roles supported and optimized!

Page 47: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

check the API diffs!

● check diffs from API Level “L Preview” to API Level 21 (shown)

● also check diffs from API Level 20 to

API Level 21

Page 48: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Optimizing for Power in Android 5.0

for both Scanning and Advertising

Page 49: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

android.bluetooth.le

Page 50: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Limitations? 40 characteristics 10 devices 15? notifications see:https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.0.0_r5/bta/gatt/bta_gattc_int.h

Page 51: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

some tools to debug Needs dedicated sniffer (more than one to cover advertising on several channels) see open source solution: http://ubertooth.sourceforge.net/hardware/one/

Page 52: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Enabling Bluetooth HCI packet Capture

-> /sdcard/btsnoop_hci.log

Page 53: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Some BLE Development Best Practices - don’t treat the device like a classic BT device! (won’t switch modes as quickly - remember it’s low powered) - acknowledge reads, writes (handle all callbacks) (yes the spec implies asynchronous but not always in practice) - implement retries, handle timeouts - store and manage device addresses to handle reconnects and avoid scanning each time

Page 54: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Some BLE Development Best Practices -­‐  Test against all 4.3+ devices…. include oem workarounds -­‐  When connecting multiple devices - each has associated

gatt object!

-­‐  make a decision about pre vs post 4.4.3 (major bug fixes include mac address pool exhaustion)

-­‐  NEW possible issues with BLE in Android 5.0

Page 55: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

What’s new in Bluetooth 4.1? L2CAP Dedicated Channels is a foundational feature of Bluetooth 4.1 (for future IPv6 support) Dual Mode Topology and Link Layer Topology Software Features (act as a Bluetooth Smart Ready Hub and peripheral at the same time) Low Duty Cycle Directed Advertising, L2CAP Connection Oriented Channels (improves efficiency)

Page 56: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Just finalized: Bluetooth 4.2 Power and Privacy features: - Low-power IP connectivity over Bluetooth with a new profile which supports IPv6 and 6LoWPAN - Allows MAC address of Bluetooth devices to be masked unless connecting to a trusted device. At the same time, the new devices will have additional refinements to reduce power consumption as part of the Low Energy Privacy 1.2 spec

Page 57: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

BLE Resources and references https://d.android.com/guide/topics/connectivity/bluetooth-le.html http://processors.wiki.ti.com/index.php/Bluetooth_SensorTag http://www.htcdev.com/devcenter/opensense-sdk/bluetooth-smart http://developer.bluetooth.org https://github.com/AltBeacon

Page 58: Best Practices and what's new in Android 5files.meetup.com/17404842/Android+BLE_DarioLaverde...BLE and Android Prior to Android 4.3, several OEMs already have devices on the market

Q & A

contact: http://google.com/+DarioLaverde