spacecheese / bluez_peripheral

A library for building BLE peripherals using GATT and bluez
MIT License
38 stars 8 forks source link

Write/Read Characteristic #24

Closed tilersmyth closed 1 year ago

tilersmyth commented 1 year ago

My gatt client sends a write request that is looking for a response and I'm using something like the following code:

@characteristic(uuid, CharFlags.WRITE | CharFlags.READ)
def on_read(self):
    return bytes("read value", "utf-8")

@on_wifiscan_request.setter
def on_write(self, value, options):
    print("write value: ", value)

Shouldn't this work? The write part works but nothing is returned. I'm sure I'm missing something but I've been racking my brain trying to figure this out and I couldn't find an example to handle this scenario. thanks for any help.

spacecheese commented 1 year ago

Hi. To confirm you're trying to implement a write followed by some kind of callback? Are you looking for something analogous to Bleno? A WRITE | READ won't do this on it's own- the read also needs triggering by the client. You could probably do this with a WRITE | NOTIFY though your client will need to subscribe to the characteristic.

Alternatively you might want a RELIABLE_WRITE but to be honest I'm not sure if that uses read or not. It's possible it might use the value property on the the characteristic interface though I think it's probably handled lower down the protocol stack. I will try and investigate this more thoroughly at some point.