Created
January 19, 2018 12:33
-
-
Save jhagberg/02416512b5c1d9cd38af66f92842da0c to your computer and use it in GitHub Desktop.
MIija Bluetooth temphumsensor read out. using gatt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gatt | |
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() | |
device_information_service = next( | |
s for s in self.services | |
if s.uuid == '226c0000-6476-4566-7562-66734470666d') | |
temp_hum_characteristic = next( | |
c for c in device_information_service.characteristics | |
if c.uuid == '226caa55-6476-4566-7562-66734470666d') | |
temp_hum_characteristic.enable_notifications() | |
def characteristic_value_updated(self, characteristic, value): | |
print( value.decode("utf-8")) | |
device = AnyDevice(mac_address='', manager=manager) | |
device.connect() | |
manager.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment