2

I'm trying to get some values from bluetooth in Python, my problem basically is when I tried to read the data from bluetooth, in this two lines:

value = bytes(await connection.client.read_gatt_char(read_characteristic))
print(value)

it prints: b'\x91'

I tried to use: valueprint = str(value).encode()

But just printed me this: "b'\x91'"

Then I tried print("Value: {0}%".format(int(value[0])))

But it gave me 145 which is not the value that I sent, I put a value 657 to run some test.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    You need to show how you are creating `txChar`. In the reference you linked to it uses `BLEByteCharacteristic`. `BLEByteCharacteristic` is for sending a single byte. If you want to send byte arrays, use `BLECharacteristic` or `BLEUnsignedShortCharacteristic` to send an integer of two bytes. – ukBaz Jun 26 '21 at 22:01
  • I updated the post, it is my full code in Arduino. I'm a beginner using this library so if yo can help me with this. It would be amazing. –  Jun 26 '21 at 22:58
  • 2
    I don't have the correct Arduino board to test this but from looking at the documentation I would have thought using `BLEUnsignedShortCharacteristic txChar(uuidOfTxChar, BLERead);` would be the only line that needs change. As a side note, the UUIDs used for the custom service and characteristics are in the reserved range used for officially adopted services. More details at: https://www.novelbits.io/uuid-for-custom-services-and-characteristics/ – ukBaz Jun 27 '21 at 06:36

0 Answers0