Skip to content

read characteristic value #61

Description

@abhatikar

Hello,

I am running this code on my peripheral that sends battery level periodically. But I am not able to get it.
A simple read_val also does not work. Please help.

Ubuntu 18.04

import gatt
from argparse import ArgumentParser

class AnyDevice(gatt.Device):
    def services_resolved(self):
        super().services_resolved()

        battery_information_service = next(
            s for s in self.services
            if s.uuid == '00001801-0000-1000-8000-00805f9b34fb')

        for c in battery_information_service.characteristics:
            c.enable_notifications(True)

        print("Reading Battery")

    def characteristic_value_updated(self, characteristic, value):
        print("Battery level:", value.decode("utf-8"))


arg_parser = ArgumentParser(description="GATT Read Firmware Version Demo")
arg_parser.add_argument('mac_address', help="MAC address of device to connect")
args = arg_parser.parse_args()

manager = gatt.DeviceManager(adapter_name='hci0')

device = AnyDevice(manager=manager, mac_address=args.mac_address)
device.connect()

manager.run()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions