b3b / able

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

Unable to send string data #21

Closed dwmoffatt closed 3 years ago

dwmoffatt commented 3 years ago

In java you can send string data via the write characteristic, in able you are unable to via the write characteristic.

Had to write my own function to do it.

b3b commented 3 years ago

The write_characteristic function should do this: https://able.readthedocs.io/en/latest/#able.BluetoothDispatcher.write_characteristic

dwmoffatt commented 3 years ago

that function calls this https://github.com/b3b/able/blob/b75a5a9c435799aaa2aa467676097860fbdc2ffb/able/utils.py#L4 which returns nothing as it doesn't convert the python String

b3b commented 3 years ago

force_convertible_to_java_array converts string to list:

>>> from able.utils import force_convertible_to_java_array
>>> force_convertible_to_java_array('test string')
['t', 'e', 's', 't', ' ', 's', 't', 'r', 'i', 'n', 'g']
dwmoffatt commented 3 years ago

Let me re-try it then. Last time I did it, it wasn't working.

b3b commented 3 years ago

Yes, it wasn't working. Array of strings is not suitable for jnius.convert_pyarray_to_java. Fixed, now it is possible to use write_characteristic with a string data.

dwmoffatt commented 3 years ago

Sweet! I will update and try it out.