Skip to content

Commit c562e2d

Browse files
committed
Allow different types of write
Some devices are sensitive about the type of write performed. Add support for choosing whether or not a response is requested.
1 parent e1b147d commit c562e2d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

gatt/gatt_linux.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -596,21 +596,28 @@ def read_value(self, offset=0):
596596
error = _error_from_dbus_error(e)
597597
self.service.device.characteristic_read_value_failed(self, error=error)
598598

599-
def write_value(self, value, offset=0):
599+
def write_value(self, value, offset=0, with_response=True):
600600
"""
601601
Attempts to write a value to the characteristic.
602602
603603
Success or failure will be notified by calls to `write_value_succeeded` or `write_value_failed` respectively.
604604
605605
:param value: array of bytes to be written
606606
:param offset: offset from where to start writing the bytes (defaults to 0)
607+
:param with_response: whether a response should be requested for the write (defaults to True)
607608
"""
608609
bytes = [dbus.Byte(b) for b in value]
609610

611+
if with_response == True:
612+
write_type = "request"
613+
else:
614+
write_type = "command"
615+
610616
try:
611617
self._object.WriteValue(
612618
bytes,
613-
{'offset': dbus.UInt16(offset, variant_level=1)},
619+
{'offset': dbus.UInt16(offset, variant_level=1),
620+
'type': write_type},
614621
reply_handler=self._write_value_succeeded,
615622
error_handler=self._write_value_failed,
616623
dbus_interface='org.bluez.GattCharacteristic1')

0 commit comments

Comments
 (0)