I have a AS97 fitness-watch and want to receive the activity data with a raspberry pi using pygatt.
I have to write to the custom services uuids.
I need device.char_write
to uuid ff01 and receive the indication from ff02.
If I just use device.char_read
, I only get the first indication.
I tried the function device.subscribe
but this doesn't work.
#!/usr/bin/env python3
import pygatt
import logging
from binascii import hexlify
from time import sleep
logging.basicConfig()
logging.getLogger('pygatt').setLevel(logging.DEBUG) # Logger to see the debug
watch = "C4:C1:88:F8:58:59" # watch bluetooth-adress
adapter = pygatt.GATTToolBackend()
adapter.start() # start bluetooth
device = adapter.connect(watch, address_type=pygatt.BLEAddressType.random, timeout=20)
#connects with watch
try:
device.char_write('7905ff01-b5ce-4e99-a40f-4b1e122d00d0',
bytearray([0xBE, 0x02, 0x01, 0xFE, 0x07, 0xE6, 0x01, 0x19, 0x00,
0x00])) #command bytes - 07e6 year - 01 month
# - 19 day - 0000 - minute start
activity_data = device.char_read('7905ff02-b5ce-4e99-a40f-4b1e122d00d0')
except:
print("Can't read informations")
adapter.stop()
print(activity_data)
adapter.stop()
I received the first indication:
bytearray(b'\xde\x02\x01\xfe\x07\xe6\x01\x19\x00\x00\x0bz\x00\x00\x07M\x00\xc8\x00')
Get activity data 2nd 3rd indication
I guess the read function didnt work well because the characteristic just use write and indication.
Thanks all for help!
I tried also something like:
def data_handler_cb(handle, value):
print("Data: {}".format(value.hex()))
print("Handle: {}".format(handle))
try:
device.char_write('7905ff01-b5ce-4e99-a40f-4b1e122d00d0',
bytearray([0xBE, 0x02, 0x01, 0xFE, 0x07, 0xE6, 0x01, 0x19, 0x00, 0x00]))
device.subscribe("7905ff02-b5ce-4e99-a40f-4b1e122d00d0", callback=data_handler_cb, indication = True)
print("Wait for callback")
sleep(3)
finally:
adapter.stop()
I also switched the order and first subscribe, but then it waits
DEBUG:pygatt.device:Looking up handle for characteristic 7905ff02-b5ce-4e99-a40f-4b1e122d00d0
DEBUG:pygatt.device:Found <Characteristic uuid=7905ff02-b5ce-4e99-a40f-4b1e122d00d0 handle=26>
DEBUG:pygatt.backends.gatttool.gatttool:Sending cmd=char-write-req 0x1b 0200
and breaks with an Error:
ERROR:pygatt.backends.gatttool.gatttool:No response received