class Nuimo: def __init__(self, macAddress='FA:48:12:00:CA:AC'): self.macAddress = macAddress def connect(self): try: self.peripheral = Peripheral(self.macAddress, addrType='random') except BTLEException: return False try: self.enableNotifications() self.peripheral.setDelegate(NuimoDelegate()) except BTLEException: self.peripheral.disconnect() self.peripheral = None return False return True def enableNotifications(self): self.peripheral.writeCharacteristic(CLICK_NOTIFICATION_HANDLE, NOTIFICATION_ON) self.peripheral.writeCharacteristic(BATTERY_NOTIFICATION_HANDLE, NOTIFICATION_ON) self.peripheral.writeCharacteristic(FLY_NOTIFICATION_HANDLE, NOTIFICATION_ON) self.peripheral.writeCharacteristic(SWIPE_NOTIFICATION_HANDLE, NOTIFICATION_ON) self.peripheral.writeCharacteristic(ROTATION_NOTIFICATION_HANDLE, NOTIFICATION_ON) def waitForNotifications(self): try: self.peripheral.waitForNotifications(1.0) return True except BTLEException as e: return False def displayLedMatrix(self, matrix, brightness, timeout): self.peripheral.writeCharacteristic(LEDMATRIX_VALUE_HANDLE, struct.pack("BBBBBBBBBBBBB", 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff))
from bluepy.bluepy.btle import UUID, Peripheral p = Peripheral("28:84:fa:97:0f:f8") svc = p.getServiceByUUID(uuid="2B1DA6DE-9C29-4D6C-A930-B990EA2F12BB") ch = svc.getCharacteristics(uuid="7F855F82-9378-4508-A3D2-CD989104AF22")[0] ch.write() while 1: if p.waitForNotifications(1.0): continue print "waiting"