Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bluetooth LE Matures in Android Lollipop

Dave Smith
November 18, 2014

Bluetooth LE Matures in Android Lollipop

Walkthrough of the updates and changes made to the Bluetooth LE APIs in Android 5.0+.

Dave Smith

November 18, 2014
Tweet

More Decks by Dave Smith

Other Decks in Programming

Transcript

  1. Android Lollipop: Bluetooth LE Matures Dave Smith @devunwired 1 Get

    the Examples: h.p://github.com/devunwired/accessory-samples
  2. GATT Profile Service <16-bit AssignedNumber> Service <UUID> GATT Peripheral 3

    CharacterisHc Proper&es Value CharacterisHc Proper&es Value CharacterisHc Proper&es Value CharacterisHc Proper&es Value CharacterisHc Proper&es Value CharacterisHc Proper&es Value CharacterisHc Proper&es Value CharacterisHc Proper&es Value
  3. Bluetooth UUIDs • Everything has a UUID – Adopted services

    are 16-bit added to a common 128-bit base: • 00000000-0000-1000-8000-00805F9B34FB – Custom services can be any generated UUID • Example SIG UUIDs – Health Thermometer Service: 0x1809 – Link Loss Service: 0x1803 – Battery Level Characteristic: 0x2A19 – Date Time Characteristic: 0x2A08 • Full Thermometer UUID – 00001809-0000-1000-8000-00805F9B34FB 4
  4. Lollipop Scanning Improvements 5 Scans: Filter AdverHsed Service UUIDs Scans:

    Filter on ANY AdverHsed Field Receive Single Device AdverHsement per Scan Receive All AdverHsements during a Scan Manual Scan Record Parsing ScanRecord & AdverHseData + Builders AcHve Scanning Only Scan Result Batching
  5. GATT Discovery 7 BluetoothDevice BluetoothAdapter BluetoothGatt Async Scan startLeScan(ScanCallback) stopLeScan()

    ScanCallback.onLeScan() connectGatt(GattCallback) Async Scan startLeScan(ScanCallback) stopLeScan(ScanCallback) ScanCallback.onScanResult() BluetoothLeScanner
  6. GATT Discovery 8 BluetoothGattCallback BluetoothGatt BluetoothGattService BluetoothGattCharacteristic BluetoothGattDescriptor discoverServices() onServicesDiscovered()

    getServices() getService(UUID) getCharacteristics() getCharacteristic(UUID) getDescriptors() getDescriptor(UUID)
  7. GATT Transactions 9 BluetoothGattCallback BluetoothGattCharacteristic BluetoothGattDescriptor BluetoothGatt readCharacteristic() writeCharacteristic() readDescriptor()

    writeDescriptor() setCharacteristicNotification() onCharacteristicRead() onCharacteristicWrite() onCharacteristicChanged() onDescriptorRead() onDescriptorWrite()
  8. Advertising 10 BluetoothAdapter BluetoothLeAdvertiser Broadcast startAdvertising(AdvertiseData) stopAdvertising() Adver?seData Device Name

    TX Power Level Manufacturer Data Service UUIDs Service Data Adver?seSeBngs TX Power Level Connectable Timeout Latency Mode
  9. Advertisement Data 11 AD Length AD Type AD Payload AD

    Structure AD Structure AD Structure ... AD Structure public void onLeScan(BluetoothDevice, int rssi, byte[] scanRecord) Type IdenHfiers are Assigned Numbers by the Bluetooth SIG Device Name, Service UUIDs, Service Data, TX Power, etc. h]ps://www.bluetooth.org/en-us/specificaHon/assigned-numbers/generic-access-profile
  10. Stack Metrics • Constants defined in BlueDroid • Max concurrent

    active notifications (BTA_GATTC_NOTIF_REG_MAX) – (4) Android 4.3 – (7) Android 4.4 – (15) Android 5.0+ • Max concurrent GATT connections (BTA_GATTC_CONN_MAX) – (4) Android 4.3 – (7) Android 4.4+ 12
  11. Come Find Me! • Dave Smith • Twitter: @devunwired •

    Google+: http://plus.google.com/+DaveSmithDev • Blog: http://wiresareobsolete.com • Beacon Hardware – http://www.kstechnologies.com/ • Samples – http://www.github.com/devunwired/accessory-samples • I/O Byte on Lollipop BLE Features – http://youtu.be/2fZThdNbHcQ 14