pygatt icon indicating copy to clipboard operation
pygatt copied to clipboard

What is the equivalent to my usual bash commands

Open dorealex opened this issue 4 years ago • 3 comments

What would be the pygatt equivalent to running:

sudo gatttool -t random -b D2:C5:26:66:6C:7D --char-write-req -a 0x2f -n 03170101

So far in python I have, I am struggling with the handle and value, I know 0x2f=47, so I passed that (would rather pass 0x2f, no big deal) but I am stumped for the value setting. It doesn't want to accept a string

YOUR_DEVICE_ADDRESS = "D2:C5:26:66:6C:7D"
# Many devices, e.g. Fitbit, use random addressing - this is required to
# connect.
ADDRESS_TYPE = pygatt.BLEAddressType.random

adapter = pygatt.GATTToolBackend()
adapter.start()
device = adapter.connect(YOUR_DEVICE_ADDRESS, address_type=ADDRESS_TYPE)

device.char_write_handle(handle=47, value = '03170101')

I also tried with device.char_write(characteristic, bytearray([0x2f, 03170101]), wait_for_response=True) But I just can't seem to pass that value...

dorealex avatar Apr 17 '21 04:04 dorealex

@dorealex Did you ever work this out? as I am having the same issue...

karl0ss avatar Oct 25 '21 15:10 karl0ss

@karl0ss unfortunately I don't think I ever got around this. I think I ended up just popping the command in a shell script and then running that script from python... This is what I did

dorealex avatar Oct 27 '21 01:10 dorealex

I forgot to add that bleak may also help you:

https://github.com/hbldh/bleak

dorealex avatar Oct 27 '21 13:10 dorealex