在重新审视这个问题后,我发现在添加了一些延迟后,我能够订阅这个特性:
以下是代码:-
import pygatt
import time
from binascii import hexlify
adapter = pygatt.BGAPIBackend()
def handle_data(handle, value):
"""
handle -- integer, characteristic read handle the data was received on
value -- bytearray, the data returned in the notification
"""
print("Received data: %s" % hexlify(value))
try:
time.sleep(5)
adapter.start()
time.sleep(5)
device = adapter.connect('xx:xx:xx:xx:xx:xx')
time.sleep(5)
device.subscribe("845ce63c-d003-423c-8922-818676d34255",
callback=handle_data)
time.sleep(5)
while 1:
pass
finally:
print("Adapter Stopped")
adapter.stop()