Auri M
Auri M

Reputation: 23

Cannot read value of BlueZ characteristic

I'm having an issue where I can't read the value of a characteristic within a GATT server. the ReadValue() method in the TxCharacteristic (shown below) doesn't seem to get called at all and nothing returns even if I insert a test value for the return.

What I'm wondering is; why does the no longer work even though I'm almost sure I haven't changed from the previous working code and how can this be fixed?

here is the class for TxCharacteristic within my code. this is being run on a Raspberry Pi 3B. the BLE scanner I am using LightBlue. Full code can be found here in the file "Firmware.py"

class TxCharacteristic(Characteristic):
"""
Transmit characteristic, sends data to the client
"""
TX_CHRC_UUID = '0x0002'

def __init__(self, bus, index, service):
    Characteristic.__init__(
            self, bus, index,
            self.TX_CHRC_UUID,
            ['read', 'notify'],
            service)
    self.notifying = False
    self.value = ""

def StartNotify(self):
    if self.notifying:
        print('Already notifying, nothing to do')
        return

    self.notifying = True

def StopNotify(self):
    if not self.notifying:
        print('Not notifying, nothing to do')
        return
    self.notifying = False

def ReadValue(self):
    print("Tx read: " + bytes(self.value).decode)
    self.value = Comms.TxRead(Comms)
    return self.value

Also, as a side issue, I don't think I have implemented notifications correctly, so any help there would also be great.

TIA, Auri

Upvotes: 1

Views: 377

Answers (1)

Auri M
Auri M

Reputation: 23

So, it turns out that the return value for ReadValue() needs to be an array of dbus.Byte objects. once I changed my code to fit this, things worked.

Upvotes: 1

Related Questions