Writing Bluetooth Mobile Apps Vincent Gao, Bluetooth SIG, Inc. Bluetooth SIG Proprietary 1
Agenda Bluetooth Smart Ready application development overview Platform support ios Android Windows Phone Cross platform Best practices for Smart Ready apps. Bluetooth SIG Proprietary 2
Typical Bluetooth Application Flow Smart Device (peripheral) Advertises Itself Smart Ready Hub (central) Scans for Advertisements Smart Ready Hub requests a Connection Smart Device accepts Connection request 1 2 3 Discover Explore Interact Bluetooth SIG Proprietary 3
Bluetooth 4.1 GAP--Central: Peripheral GATT--Client : Server LL--Master: Slave Bluetooth SIG Proprietary 4
It s all about data 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 Bluetooth SIG Proprietary 5
Workflow of a Bluetooth app----central Scan Connect interact. Connect or Advertise? Subscription and Notification. Bandwidth and data type. Understanding GAP. Bluetooth SIG Proprietary 6
Workflow of a Bluetooth Smart app----central Advertising Scanning/Connecting Callback Get services/characteristics' Callback Write to values Callback Sending notifications Callback Bluetooth SIG Proprietary 7
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? On_Resume Close connection Bluetooth SIG Proprietary 8
Platform Overview version ios Android Windows Phone ios 4 and up 4.4 8.1 BLE roles Central/perip Central Central heral Connection up to 6 no limit no limit Backgroundin Yes Yes Yes g Reconnect Yes Yes Yes Security Connection param Secure/Insecure connection Bluetooth SIG Proprietary 9
ios Support both central and peripheral Backgrounding Publishing and advertising Connection parameter MFi not required Caching What does those mean to the developers. Bluetooth SIG Proprietary 10
ios 7 Scanning/Connecting Get services/characteristics' Write to values (void) (void) getallcharacteristicsfromperipheral:(cbperipheral connectperipheral:(cbperipheral *)peripheral status:(bool)status{ *)p if(status [p writevalue:data == TRUE) forcharacteristic:characteristic { type:cbcharacteristicwritewithoutresponse]; { for (int i=0; i < p.services.count; i++) { CBService activeperipheral *s = [p.services = peripheral; objectatindex:i]; printf("fetching activeperipheral.delegate characteristics for = self; service with UUID : %s\r\n",[self CBUUIDToString:s.UUID]); [CM connectperipheral:activeperipheral options:nil]; } [p discovercharacteristics:nil forservice:s]; } Bluetooth SIG Proprietary 11
Best Practices on ios Core Bluetooth Throughput CBCharacteristicWriteWithoutResponse CONNECTION UPDATE Connectionless Energy efficient Scan Bluetooth SIG Proprietary 12
Demo Application accelerator Application debugging using sniffers. Bluetooth SIG Proprietary 13
Android Starts support Bluetooth Smart Ready since 4.3 Adopted Profiles and custom profiles. Permissions. Time out for most of the operations. Some known issues. Bluetooth SIG Proprietary 14
Android Scanning/Connecting Get services/characteristics' Write to values public boolean connect(final String deviceaddress) { public if (mbluetoothadapter void getsupportedservices() writedatatocharacteristic(final == null { deviceaddress BluetoothGattCharacteristic == null) return false; ch, if(mbluetoothgattservices final byte[] d atowrite)!= { null && mbluetoothgattservices.size() > 0) mdeviceaddress = deviceaddress; mbluetoothgattservices.clear(); if (mbluetoothadapter == null mbluetoothgatt == null ch == null) return; // keep reference to all services in local array: // connect if(mbluetoothgatt from scratch!= null) mbluetoothgattservices = mbluetoothgatt.getservices(); // first // set get it BluetoothDevice locally... object for specified address ch.setvalue(datatowrit muicallback.uiavailableservices(mbluetoothgatt, mbluetoothdevice = ); mbluetoothadapter.getremotedevice(mdeviceaddress); mbluetoothdevice, mbluetoothgattservices); } //... if and (mbluetoothdevice then "commit" changes == to null) the peripheral { mbluetoothgatt.writecharacteristic(ch); // we got wrong address - that device is not available! } return false; } // connect with remote device } mbluetoothgatt = mbluetoothdevice.connectgatt(mparent, false, mblecallback); } return true; Bluetooth SIG Proprietary 15
WinRT and the 8.1 update Unified Windows Device Model Connection limitation Code walk-through Bluetooth SIG Proprietary 16
Cross Platform Solution PhoneGap/Cordova demo Bluetooth SIG Proprietary 17
Best Practices Be energy efficient. Scanning Reconnect Advertising Fast connection Back grounding. Connection parameters App publishing Bluetooth SIG Proprietary 18
Resources on the Portal Knowledge Center White papers Training Videos Development Resources Quick Start Kit Application Accelerator Smart Starter Kit Recorded webinars on development topics Links to SIG tools (PTS, etc.) Forums GATT specifications http://developer.bluetooth.org Bluetooth SIG Proprietary 19
Bluetooth SIG Proprietary and Confidential 20