able icon indicating copy to clipboard operation
able copied to clipboard

Receiving data through notifications

Open ilw opened this issue 2 years ago • 1 comments

Hi, I really love the simplicity of this library for managing a GATT client. I just wanted to check my understanding about receiving data through notifications. Am i right in thinking that i enable it with "enable_notifications" (in dispatcher.py) and then "on_characteristic_changed" (in dispatcher.py) will be called when a notification for that characteristic is received. So i just have to somehow override the stub callback function "on_characteristic_changed" to handle the data being received?

Thanks!

ilw avatar Feb 28 '22 14:02 ilw

Hi @ilw , Yes, you are right, that's how it's supposed to work.

class BLE(able.BluetoothDispatcher):

    def on_services(self, status, services):
        characteristic = self.services.search("aaaa")
        if self.enable_notifications(characteristic):
            Logger.info("Notifications enabled")

    def on_characteristic_changed(self, characteristic):
        data = characteristic.getStringValue(0)

And here is example of usage in the BLE functions testing app: https://github.com/b3b/able/blob/master/testapps/bletest/main.py#L222

b3b avatar Feb 28 '22 21:02 b3b