本文整理汇总了Python中bluepy.btle.Peripheral.withDelegate方法的典型用法代码示例。如果您正苦于以下问题:Python Peripheral.withDelegate方法的具体用法?Python Peripheral.withDelegate怎么用?Python Peripheral.withDelegate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bluepy.btle.Peripheral
的用法示例。
在下文中一共展示了Peripheral.withDelegate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from bluepy.btle import Peripheral [as 别名]
# 或者: from bluepy.btle.Peripheral import withDelegate [as 别名]
for i in range(0, longueur, 5):
self.read_val(dft_treated, i)
if __name__ == "__main__":
rx_uuid = UUID(0x2221)
sample_size = 128
# p = Peripheral("D9:35:6A:75:9F:9D", "random") # Rfduino sur usb
continuer = True
while(continuer):
try:
p = Peripheral("D1:7F:06:ED:66:DC", "random") # Rfduino sur pcb
continuer = False
except:
print "Module bluetooth deja connecte, nouvel essai dans 3 sec..."
time.sleep(3)
p.withDelegate(MyDelegate())
Analyser.set_p(p)
print " device connected..."
try:
p.getServices()
ch = p.getCharacteristics(uuid=rx_uuid)[0]
print ("notify characteristic with uuid 0x" + rx_uuid.getCommonName())
cccid = btle.AssignedNumbers.client_characteristic_configuration
# Ox000F : handle of Client Characteristic Configuration descriptor Rx - (generic uuid 0x2902)
p.writeCharacteristic(0x000F, struct.pack('<bb', 0x01, 0x00), False)
if ch.supportsRead():
while 1:
p.waitForNotifications(604800) # 1 semaine d'attente
# handleNotification() was called
示例2: NotifyDelegate
# 需要导入模块: from bluepy.btle import Peripheral [as 别名]
# 或者: from bluepy.btle.Peripheral import withDelegate [as 别名]
class YeelightService:
"""
YeelightService is the yeelight control util for python
author zhaohui.sol
"""
SERVICE = "0000FFF0-0000-1000-8000-00805F9B34FB"
CHAR_CONTROL = "0000FFF1-0000-1000-8000-00805F9B34FB"
CHAR_DELAY = "0000FFF2-0000-1000-8000-00805F9B34FB"
CHAR_DELAY_QUERY = "0000FFF3-0000-1000-8000-00805F9B34FB"
CHAR_DELAY_NOTIFY = "0000FFF4-0000-1000-8000-00805F9B34FB"
CHAR_QUERY = "0000FFF5-0000-1000-8000-00805F9B34FB"
CHAR_NOTIFY = "0000FFF6-0000-1000-8000-00805F9B34FB"
CHAR_COLOR_FLOW = "0000FFF7-0000-1000-8000-00805F9B34FB"
CHAR_NAME = "0000FFF8-0000-1000-8000-00805F9B34FB"
CHAR_NAME_NOTIFY = "0000FFF9-0000-1000-8000-00805F9B34FB"
CHAR_COLOR_EFFECT = "0000FFFC-0000-1000-8000-00805F9B34FB"
class NotifyDelegate(DefaultDelegate):
def __init__(self):
DefaultDelegate.__init__(self)
self.queue = list()
def register(self,callback):
self.queue.append(callback)
def deregister(self,callback):
self.queue.remove(callback)
def handleNotification(self,handle,data):
logging.warning("notify data %s from %s." % (data,handle))
res = dict()
res['data'] = data
res['handle'] = handle
for c in self.queue:
c(res)
def __init__(self,address):
"""
address is the yeelight blue ble hardware address
"""
self.data = dict()
self.address = address
self.delegate = YeelightService.NotifyDelegate()
self.peripher = Peripheral(deviceAddr = address)
self.service = self.peripher.getServiceByUUID(YeelightService.SERVICE)
self.peripher.withDelegate(self.delegate)
def __character_by_uuid__(self,uuid):
'''
get character by a special uuid
'''
characters = self.service.getCharacteristics(forUUID=uuid)
return characters[0] if characters else None
def __write_character__(self,uuid,strdata):
'''
write data to a special uuid
'''
logging.info(u"write %s to %s." % (strdata,uuid))
character = self.__character_by_uuid__(uuid)
if character:
character.write(strdata)
else:
pass
def __read_character__(self,uuid):
'''
read data from a special uuid,may be it's wrong
'''
logging.info(u"read data from %s." % uuid)
character = self.__character_by_uuid__(uuid)
if character:
return character.read()
else:
return None
def __notify_character__(self,_to,_write):
'''
write data to the uuid and wait data notify
'''
res = dict()
def callback(data):
for k in data:
res[k] = data[k]
self.delegate.register(callback)
self.__write_character__(_to,_write)
#.........这里部分代码省略.........