-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathread_firmware_version.py
More file actions
33 lines (21 loc) · 994 Bytes
/
read_firmware_version.py
File metadata and controls
33 lines (21 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gatt
from argparse import ArgumentParser
class AnyDevice(gatt.Device):
def services_resolved(self):
super().services_resolved()
device_information_service = next(
s for s in self.services
if s.uuid == '0000180a-0000-1000-8000-00805f9b34fb')
firmware_version_characteristic = next(
c for c in device_information_service.characteristics
if c.uuid == '00002a26-0000-1000-8000-00805f9b34fb')
firmware_version_characteristic.read_value()
def characteristic_value_updated(self, characteristic, value):
print("Firmware version:", 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()