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

Promisified BLE Client

Masayuki Izumi
September 16, 2015

Promisified BLE Client

Introduce Bletia: Promisified BLE Client for Android
potatotips #21 http://connpass.com/event/18732/
Bletia https://github.com/izumin5210/Bletia

Masayuki Izumi

September 16, 2015
Tweet

More Decks by Masayuki Izumi

Other Decks in Programming

Transcript

  1.  Rekimoto Lab. at the University of Tokyo (2008-2015: Akashi-NCT)

     Enginner at Wantedly, Inc. (2014.9-2015.2: Dmetlabel, Inc.) 2
  2. Write characteristic value Central wants data Peripheral has data write

    value BluetoothGatt#writeCharacteristic() (async)
  3. Write characteristic value Central wants data Peripheral has data write

    value BluetoothGatt#writeCharacteristic() BluetoothGattCallback#onCharacteristicWrite() (async)
  4. When is the callback registered ? public BluetoothGatt connectGatt (

    Context context, boolean autoConnect, BluetoothGattCallback callback )
  5. When is the callback registered ? public BluetoothGatt connectGatt (

    Context context, boolean autoConnect, BluetoothGattCallback callback ) We can register only 1 instance...
  6. Handle callback public void onCharacteristicWrite ( BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,

    int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // check characteristic instance, handling... } else { // error handling... } }
  7. Handle callback public void onCharacteristicWrite ( BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,

    int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // check characteristic instance, handling... } else { // error handling... } }
  8. if BG has promise like api ... gatt.writeCharacteristic(characteristic) .then( //

    call when the operation successfully ) .fail( // call when the operation failure )
  9. Instantiate / Connect // Pass application context to constructor. Bletia

    bletia = new Bletia(context); // BluetoothDevice device bletia.connect(device);