b3b / able

Python for Android Bluetooth Low Energy package
MIT License
39 stars 18 forks source link

Need function for write characteristic no response or example how to do it #17

Closed dwmoffatt closed 4 years ago

dwmoffatt commented 4 years ago

I see that there is a function in BLE.java but not sure how to access it in able as I dont see a function for it.

b3b commented 4 years ago

Since characteristics are pyjnius reflections of BluetoothGattCharacteristic Java objects (https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic), it is possible to call:

characteristic.setWriteType(1)  #  WRITE_TYPE_NO_RESPONSE = 1

before the ble.write_characteristic(characteristic, '...')

Or, more clearly:

from jnius import autoclass
BluetoothGattCharacteristic = autoclass('android.bluetooth.BluetoothGattCharacteristic')
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE)
ble.write_characteristic(characteristic, '...')

Currently, writeCharacteristicNoResponse is not exposed from BLE.java. I think this method is redundant, and should be just deleted.

dwmoffatt commented 4 years ago

Thank you for the example! Going to try it right now!

On Sun., Nov. 8, 2020, 3:13 p.m. b3b, notifications@github.com wrote:

Since characteristics are pyjnius reflections of BluetoothGattCharacteristic Java objects ( https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic), it is possible to call:

characteristic.setWriteType(1) # WRITE_TYPE_NO_RESPONSE = 1

before the ble.write_characteristic(characteristic, '...')

Or, more clearly:

from jnius import autoclassBluetoothGattCharacteristic = autoclass('android.bluetooth.BluetoothGattCharacteristic')characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE)ble.write_characteristic(characteristic, '...')

Currently, writeCharacteristicNoResponse is not exposed from BLE.java. I think this method is redundant, and should be just deleted.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/b3b/able/issues/17#issuecomment-723680526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMT5T46GKAD7UJONRM6OVYDSO4QZ7ANCNFSM4TODMD7Q .

dwmoffatt commented 4 years ago

Worked! This library is awesome by the way!

b3b commented 4 years ago

Added a new option for convenience:

from able import WriteType
ble.write_characteristic(characteristic, '...', write_type=WriteType.NO_RESPONSE)