I’m using Python with the Bleak library to write a bytearray to a Bluetooth device characteristic. The bytearray I’m sending is
bytearray(b'3x01x00-x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x1f')
However, in Flutter, I’m using the flutter_blue_plus package, which expects a list of integers to write to a characteristic. For example,
await c.write([0x12, 0x34])
is used in Flutter to write. How can I convert the Python bytearray to a format suitable for the write method in Flutter?
Note: I’ve tried following in flutter, but in vain.
Wrote:
await c.write([3, 1, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31]);
Response:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Wrote:
await c.write([51, 1, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31],);
Responses:
[51, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50]
[238, 1, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 231]
Abdullah Saeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.