I am trying to subscribe to a GATT characteristic.
I have set the \"Indicate\", \"Notify\" and \"Read\" attributes for the GATT characteristic in my BLE device.
After revisiting this issue, i found that after adding some delays, i was able to subscribe to the characteristic:
Following is the code:-
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()