Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import gatt
- import binascii
- manager = gatt.DeviceManager(adapter_name='hci0')
- class AnyDevice(gatt.Device):
- def connect_succeeded(self):
- super().connect_succeeded()
- print("[%s] Connected" % (self.mac_address))
- def connect_failed(self, error):
- super().connect_failed(error)
- print("[%s] Connection failed: %s" % (self.mac_address, str(error)))
- def disconnect_succeeded(self):
- super().disconnect_succeeded()
- print("[%s] Disconnected" % (self.mac_address))
- def services_resolved(self):
- super().services_resolved()
- print("[%s] Resolved services" % (self.mac_address))
- for service in self.services:
- print("[%s] Service [%s]" % (self.mac_address, service.uuid))
- for c in service.characteristics:
- print("[%s] Characteristic [%s]" % (self.mac_address, c.uuid))
- if c.uuid == '09b600b1-3e42-41fc-b474-e9c0c8f0c801':
- self.write = c
- c.write_value(bytearray([0x25, 0x00, 0x02, 0x42, 0x01, 0xff, 0x00]))
- elif c.uuid == '09b600b0-3e42-41fc-b474-e9c0c8f0c801':
- self.notify = c
- c.enable_notifications()
- def characteristic_value_updated(self, characteristic, value):
- print("characteristic_value_updated:", binascii.hexlify(value))
- def characteristic_read_value_failed(self, characteristic, error):
- print('characteristic_read_value_failed:', error)
- def characteristic_write_value_succeeded(self, characteristic):
- print('characteristic_write_value_succeeded')
- def characteristic_write_value_failed(self, characteristic, error):
- print('characteristic_write_value_failed:', error)
- def characteristic_enable_notification_succeeded(self):
- print('characteristic_enable_notification_succeeded')
- def characteristic_enable_notification_failed(self):
- print('characteristic_enable_notification_failed')
- def advertised(self):
- print('advertised')
- device = AnyDevice(mac_address='d5:a8:b5:ba:30:7a', manager=manager)
- device.connect()
- manager.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement