pygatt icon indicating copy to clipboard operation
pygatt copied to clipboard

Can't write in a characteristic using the uuid wih gatttool backend but I can using gatttool directly

Open dBeltranGeze opened this issue 8 years ago • 3 comments

I can write a value in a characteristic using gatttool in a RPI3 but I can't using a Python3 script and pygatt library.

I have a script which gets the handle passing an uuid: myBLE._device.get_handle(uuid) This returns 29.

Then I try to write myBLE._device.char_write(29, bytearray(listOfBytes)) And this returns: No characteristic found matching 29.

If I try to write the characteristic passing the uuid, nothing happens: No error and no value written.

dBeltranGeze avatar Oct 05 '18 12:10 dBeltranGeze

I think the char_write() uses uuid, not handle. See the source code below for device.py

def char_write(self, uuid, value, wait_for_response=False):
        """
        Writes a value to a given characteristic UUID.

        uuid -- the UUID of the characteristic to write to.
        value -- a bytearray to write to the characteristic.
        wait_for_response -- wait for response after writing.

        Example:
            my_ble_device.char_write('a1e8f5b1-696b-4e4c-87c6-69dfe0b0093b',
                                     bytearray([0x00, 0xFF]))
        """
        return self.char_write_handle(self.get_handle(uuid), value,
                                      wait_for_response=wait_for_response)

It seems like you want char_write_handle(), but it is not implemented in my version

def char_write_handle(self, handle, value, wait_for_response=False):
        """
        Writes a value to a given characteristic handle. This can be used to
        write to the characteristic config handle for a primary characteristic.

        hande -- the handle to write to.
        value -- a bytearray to write to the characteristic.
        wait_for_response -- wait for response after writing.

        Example:
            my_ble_device.char_write(42,
                                     bytearray([0x00, 0xFF]))
        """
        raise NotImplementedError()

wstreyer avatar Oct 12 '18 18:10 wstreyer

Sorry, I see in the last line that you already tried the uuid.

wstreyer avatar Oct 12 '18 18:10 wstreyer

A few fixes for characteristic writes landed in v4.0.0. Please give it a try and open a new issue if it's not working. Thanks!

peplin avatar Mar 30 '19 21:03 peplin