Promisified BLE Client

9eed44f137609e6ce3b6f1e14f80b9e1?s=47 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

9eed44f137609e6ce3b6f1e14f80b9e1?s=128

Masayuki Izumi

September 16, 2015
Tweet

Transcript

  1. Promisified BLE Client Masayuki IZUMI - @izumin5210 potatotips #21 https://www.flickr.com/photos/dewittkower/4641701143/

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

     Enginner at Wantedly, Inc. (2014.9-2015.2: Dmetlabel, Inc.) 2
  3. 2 Ruby JavaScript Android Design pry(main) > izumin.skill_ratio

  4. http://konashi.ux-xu.com/ https://github.com/YUKAI/konashi-android-sdk/ https://www.flickr.com/photos/36571434@N03/8524872002

  5. \ 前回のラブライブ! / kyobashi.dex

  6. https://speakerdeck.com/izumin5210/tsurai-ble-on-android

  7. Bluetooth GATT GATT Server Service Service

  8. Bluetooth GATT GATT Server Service Service Characteristic

  9. BLE on Android Central wants data Peripheral has data

  10. BLE on Android Central wants data Peripheral has data write

    value read value
  11. Write characteristic value Central wants data Peripheral has data write

    value
  12. Write characteristic value Central wants data Peripheral has data write

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

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

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

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

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

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

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

    call when the operation successfully ) .fail( // call when the operation failure )
  20. Bletia https://github.com/izumin5210/Bletia

  21. Download dependencies { compile 'info.izumin.android:bletia:1.2.2' }

  22. Instantiate / Connect // Pass application context to constructor. Bletia

    bletia = new Bletia(context); // BluetoothDevice device bletia.connect(device);
  23. Instantiate / Connect bletia.writeCharacteristic(characteristic);

  24. Write characteristic bletia.writeCharacteristic(characteristic) .then(new DoneCallback<BluetoothGattCharacteristic>() { @Override public void onDone(BluetoothGattCharacteristic

    result) { // Call when the request was successfully. } });
  25. Write characteristic bletia.writeCharacteristic(characteristic) .then(new DoneCallback<BluetoothGattCharacteristic>() { @Override public void onDone(BluetoothGattCharacteristic

    result) { // Call when the request was successfully. } });
  26. Write characteristic bletia.writeCharacteristic(characteristic) .then(new DoneCallback<BluetoothGattCharacteristic>() { @Override public void onDone(BluetoothGattCharacteristic

    result) { // Call when the request was successfully. } });
  27. Write characteristic bletia.writeCharacteristic(characteristic) .fail(new FailCallback<BletiaException>() { @OVerride public void onFail(BletiaException

    result) { // Call when the request was failure. } });
  28. Write characteristic bletia.writeCharacteristic(characteristic) .fail(new FailCallback<BletiaException>() { @OVerride public void onFail(BletiaException

    result) { // Call when the request was failure. } });
  29. Write characteristic bletia.writeCharacteristic(characteristic) .fail(new FailCallback<BletiaException>() { @OVerride public void onFail(BletiaException

    result) { // Call when the request was failure. } });
  30. Support promisified operations (v1.2.2) * readCharacteristic() / writeCharacteristic() * readDescriptor()

    / writeDescriptor() * enableNotification() * readRemoteRssi()
  31. Conclusion Saiko no Experiense with Promise