Reputation: 680
I have been trying for a while to write to a custom gatt characteristic using pygatt and a Bluegiga BLE112D.The device I'm trying to write to is also a BLE112 (not the dongle). I've been using the following python script:
import pygatt
adapter = pygatt.BGAPIBackend()
adapter = pygatt.BGAPIBackend()
adapter.start()
adapter.scan(timeout=1)
device = adapter.connect('88:6b:0f:7e:4e:66',address_type=pygatt.BLEAddressType.public)
characteristic = "8fbfa190-1af2-427c-a22b-3da61b6b7162"
device.char_write(characteristic, bytearray([0x00, 0xFF]))
#check the characteristic
value = device.char_read(characteristic)
print(value)
adapter.stop()
The characteristic I am trying to write to is configured as follows:
<service uuid="8fbfa190-1af2-427c-a22b-3da71b6b7166" advertise="true">
<description>Table</description>
<include id="manufacturer" />
<characteristic uuid="8fbfa190-1af2-427c-a22b-3da61b6b7162" id="xgatt_table">
<properties read="true" write="true" />
<value length="2" />
</characteristic>
</service>
-The script successfully connects with the adapter and the device. -I can read the characteristic just fine and no errors are produced when I write to it, but when I read the characteristic again, the value has not changed. -I've enabled logging and looked through the output, but everything there shows successful processes. -I am able to write to the characteristic using a third party BLE app as well as the blegui app
I'm pretty sure the problem resides with the pygatt script, but am at a loss as to what could be the issue.
To summarize what I'm using: Pygatt with python 3 to connect to a BLE112A through a BLE112D on windows 10.
Upvotes: 2
Views: 1636
Reputation: 680
This issue was solved by adding wait_for_response=True
as a parameter in the char_write
function. So the new write function call is:
device.char_write(characteristic, bytearray([0x00, 0xFF]), wait_for_response=True)
I'm not entirely sure why this is the case, but I believe that the script was reading from the characteristic before the new value was written.
Upvotes: 1