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

AnDevCon_Boston_Bluetooth

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for VincentGao VincentGao
May 30, 2014
96

 AnDevCon_Boston_Bluetooth

Avatar for VincentGao

VincentGao

May 30, 2014

Transcript

  1. Bluetooth SIG Proprietary and Confidential 1 Developing Android Bluetooth Smart

    Ready Apps and connect to the world of smart objects. -----Vincent Gao, Bluetooth SIG May. 2014
  2. Bluetooth SIG Proprietary and Confidential 2 Agenda • Appcessories. •

    Why do Things use Bluetooth Smart for communication. • What do we have now? • What is available on Android. • Android Bluetooth Stack. • Android devices. • What is available from the adopted profiles. • The cost of a customized/proprietary profile. • How to do it? • How to send/receive data on Android. • How to be power efficient
  3. Bluetooth SIG Proprietary and Confidential 3 * 2013 ANALYSIS OF

    THE BLUETOOTH MARKET AND INDUSTRY, ABI Research Bluetooth Smart devices/year shipped Applications for Smart Ready devices Why should I care?
  4. Bluetooth SIG Proprietary and Confidential 7 IoT and Appcessories …and

    why do they use Bluetooth Smart • Energy efficient. • Handset availability • Development cost • Form factor • Reliability
  5. Bluetooth SIG Proprietary and Confidential 8 Android is Smart Ready…A

    little history HW came first. Samsung BLE SDK. Motorola BLE SDK. HTC One SDK. Broadcom SDK. AOSP.
  6. Bluetooth SIG Proprietary and Confidential 10 GAP/GATT/Roles What does this

    mean to developers? GATT Client Central Master GATT Server Peripheral Slave GATT GAP Link Layer
  7. Bluetooth SIG Proprietary and Confidential 11 Data and State All

    data are in the attributes. Organized in the profile form. Adopted profiles and Custom profiles. What’s in a profile. – Data structure of Profile  Service  Characteristics UUID as the identifier.
  8. Bluetooth SIG Proprietary and Confidential 14 More on Android stock

    stack Central only 7 concurrent connections Raw packet available – onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) No connection parameters configuration. – Connection Interval Min – Connection Interval Max – Slave Latency – Supervision Timeout
  9. Bluetooth SIG Proprietary and Confidential 15 Typical Bluetooth Application Flow

    Smart Device (peripheral) Advertises Itself Smart Ready Hub (central) Scans for Advertisements Smart Ready Hub requests a Connection Smart Device sends connection response Discover Explore Interact 1 2 3
  10. Bluetooth SIG Proprietary and Confidential 16 Android Bluetooth Basics Scanning/Connecting

    Get services/characteristics' Read/Write values public boolean connect(final String deviceAddress) { if (mBluetoothAdapter == null || deviceAddress == null) return false; mDeviceAddress = deviceAddress; // connect from scratch // get BluetoothDevice object for specified address mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(mDeviceAddress); if (mBluetoothDevice == null) { // we got wrong address - that device is not available! return false; } // connect with remote device mBluetoothGatt = mBluetoothDevice.connectGatt(mParent, false, mBleCallback); } return true; } public void getSupportedServices() { if(mBluetoothGattServices != null && mBluetoothGattServices.size() > 0) mBluetoothGattServices.clear(); // keep reference to all services in local array: if(mBluetoothGatt != null) mBluetoothGattServices = mBluetoothGatt.getServices(); mUiCallback.uiAvailableServices(mBluetoothGatt, mBluetoothDevice, mBluetoothGattServices); } public void writeDataToCharacteristic(final BluetoothGattCharacteristic ch, final byte[] dataToWrite) { if (mBluetoothAdapter == null || mBluetoothGatt == null || ch == null) return; // first set it locally.... ch.setValue(dataToWrite); // ... and then "commit" changes to the peripheral mBluetoothGatt.writeCharacteristic(ch); }
  11. Bluetooth SIG Proprietary and Confidential 17 A checklist from the

    central side  Is Bluetooth device available?  Is Bluetooth Smart device available?  Is the device turned on?  Scan and found by UUID?  Discover service by UUID?  Read/Write value of characteristics?  Close connection
  12. Bluetooth SIG Proprietary and Confidential 18 Tips and Tricks Detect

    the correct stack and API if(Build.MANUFACTURER.equalsIgnoreCase("samsung")) { if(Build.VERSION.SDK_INT == 19) { apiVersion = BleConstant.OFFICIAL_API; } } … Intent startCorrectBleApi = new Intent(getApplicationContext(), OfficialBLEService.class);
  13. Bluetooth SIG Proprietary and Confidential 19 Tips and tricks Autoconnect

    public BluetoothGatt connectGatt (Context context, boolean autoConnect, BluetoothGattCallback callback) Backgrounding Nexus 4,5 and 7.
  14. Bluetooth SIG Proprietary and Confidential 21 Known issues: Connection using

    an existing GATT instance. – StartLeScan by UUID on Galaxy – http://stackoverflow.com/questions/17870189/android-4-3- bluetooth-low-energy-unstable autoconnect is slow but repeated manual connect calls break things One command at a time. Beacon.
  15. Bluetooth SIG Proprietary and Confidential 23 Case study: Finder •

    Proximity profile • Link loss service • Security/Pairing • Implementation • Best practice • Make it wearable.
  16. Bluetooth SIG Proprietary and Confidential 25 Case Study: Beacon •

    What’s in a Beacon. • Understand Bluetooth advertisement • Mobile OS/App • Deep dive into the source code.
  17. Bluetooth SIG Proprietary and Confidential 26 Resources on the Portal

    Knowledge Center – White papers – Training Videos Development Resources – Quick Start Kit – Application Accelerator – Platform availability for Smart and Smart Ready – Recorded webinars on development topics – Links to SIG tools (PTS, etc.) Forums GATT specifications http://developer.bluetooth.org
  18. Bluetooth SIG Proprietary and Confidential 28 Best practices • Be

    energy efficient. • Scanning • Reconnect • Advertising • Fast connection • Security • Back grounding. • Advertising.