Skip to content

read characteristic value #61

Open

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

  1. abhatikar commented on Jan 30, 2021

    @abhatikar
    Author

    Please let me know if I am missing something

  2. abhatikar commented on Jan 30, 2021

    @abhatikar
    Author

    gatttool utility seems to work. Please help how to use this library. Thanks in advance,

    gatttool -b "aa:4f:9f:55:30:00" -I
    [aa:4f:9f:55:30:00][LE]> connect
    Attempting to connect to aa:4f:9f:55:30:00
    Connection successful
    [aa:4f:9f:55:30:00][LE]> char-desc
    handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
    handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
    handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
    handle: 0x0006, uuid: 00002800-0000-1000-8000-00805f9b34fb
    handle: 0x0007, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x0008, uuid: 00002a05-0000-1000-8000-00805f9b34fb
    handle: 0x0009, uuid: 00002902-0000-1000-8000-00805f9b34fb
    handle: 0x000a, uuid: 00002800-0000-1000-8000-00805f9b34fb
    handle: 0x000b, uuid: 00002803-0000-1000-8000-00805f9b34fb
    handle: 0x000c, uuid: 00002a19-0000-1000-8000-00805f9b34fb
    handle: 0x000d, uuid: 00002902-0000-1000-8000-00805f9b34fb
    [aa:4f:9f:55:30:00][LE]> char-write-req 0x000d 0100
    Characteristic value was written successfully
    Notification handle = 0x000c value: 05
    Notification handle = 0x000c value: 04
    Notification handle = 0x000c value: 05
    Notification handle = 0x000c value: 06
    Notification handle = 0x000c value: 05
    Notification handle = 0x000c value: 04
    Notification handle = 0x000c value: 05
    Notification handle = 0x000c value: 06
    Notification handle = 0x000c value: 05
    Notification handle = 0x000c value: 06
    Notification handle = 0x000c value: 05
    Notification handle = 0x000c value: 04
    Notification handle = 0x000c value: 05
    Notification handle = 0x000c value: 04
    Notification handle = 0x000c value: 05
    [aa:4f:9f:55:30:00][LE]> disconnect
    
    
  3. changed the title [-]read characteristic[/-] [+]read characteristic value[/+] on Jan 30, 2021
  4. retorik commented on Jul 27, 2021

    @retorik

    Hi, same issue for me ! Have you found a solution ? Thx Jeremy

  5. abhatikar commented on Jul 27, 2021

    @abhatikar
    Author

    I didn't use the gatt-python. I wrote a C application to interact with BLE device.

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