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.
I am able to connect to my BLE device and read/write to other characteristics.
However, i am unable to execute the device.subscribe() function for this particular characteristic.
When i use
device.subscribe("845ce63c-d003-423c-8922-818676d34255", callback=handle_data)
i get the error
pygatt.backends.bgapi.exceptions.ExpectedResponseTimeout: Timed out
after 10.000000s waiting for
[]
In the link
https://github.com/peplin/pygatt/blob/master/pygatt/device.py, the subscribe function has the parameter "wait_for_response"
In my code, if i use
device.subscribe("845ce63c-d003-423c-8922-818676d34255", callback=handle_data, wait_for_response=True)
it shows the error
TypeError: subscribe() got an unexpected keyword argument
'wait_for_response'
How do i eliminate these errors and subscribe to the characteristic?
EDIT:
I added the properties Read and Write to the characteristic along-with Notify and Indicate
I can read and Write to the characteristic using the following code:-
import pygatt
adapter = pygatt.BGAPIBackend()
try:
adapter.start()
device = adapter.connect('xx:xx:xx:xx:xx:xx')
print("Connected")
#value = device.char_write_handle(55, bytearray([0x00,0x01]), wait_for_response=True)
value = device.char_read_handle(55)
print(value)
finally:
adapter.stop()
However, it is just that i am unable to subscribe to it.
I am really stuck here.
Any help is much appreciated!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…