示例#1
0
文件: Mip.py 项目: mi0u/Mip
 def connect(self):
   self.log.info('Connecting...')
   self.peripheral = None
   if cb.get_state() <> 5:
     self.log.warning('Bluetooth not enabled...')
     while cb.get_state() <> 5:
       time.sleep(1)
   cb.set_central_delegate(self)
   self.log.info( '## Scanning for peripherals... ##')
   with self.cv:
     cb.scan_for_peripherals()
     self.cv.wait(15)
   if not self.ready:
     self.disconnect()
     result = False
   else:
     result = True
   self.log.info(result)
   return result
示例#2
0
	def did_discover_services(self, p, error):
		cb.get_state()
		print "Name:", p.name
		print "UUID:", p.uuid
		if p.state == 0:
			print "STAT: Disconnected"
		if p.state == 1:
			print "STAT: Connecting"
		if p.state == 2:
			print "STAT: Connected"
		time.sleep(0.4)
		print "AUTH:", cb.CH_PROP_AUTHENTICATED_SIGNED_WRITES
		time.sleep(0.4)
		print "Properties:", cb.CH_PROP_EXTENDED_PROPERTIES
		time.sleep(0.4)
		print "Indicate:", cb.CH_PROP_INDICATE
		time.sleep(0.4)
		print "Encryption:", cb.CH_PROP_NOTIFY_ENCRYPTION_REQUIRED
		time.sleep(0.4)
		print "Services:"
		for s in p.services:
			print "-" + str(s.uuid)
		p.discover_characteristics(s)
示例#3
0
 def did_discover_services(self, p, error):
     print('did_discover_services({})'.format(p.name))
     cb.get_state()
     print("Name:", p.name)
     print("UUID:", p.uuid)
     try:
         state = 'Disconnected Connecting Connected'.split()[p.state]
     except IndexError:
         state = 'Invalid state ({})'.format(p.state)
     print("STAT: ", state)
     time.sleep(0.4)
     print("AUTH:", cb.CH_PROP_AUTHENTICATED_SIGNED_WRITES)
     time.sleep(0.4)
     print("Properties:", cb.CH_PROP_EXTENDED_PROPERTIES)
     time.sleep(0.4)
     print("Indicate:", cb.CH_PROP_INDICATE)
     time.sleep(0.4)
     print("Encryption:", cb.CH_PROP_NOTIFY_ENCRYPTION_REQUIRED)
     time.sleep(0.4)
     print("{} Services:".format(len(p.services)))
     for s in p.services:
         print("-" + str(s.uuid))
     p.discover_characteristics(s)
示例#4
0
def discover_BLE_characteristics(lodBLE):
	""" discover bluetooth le peripherals and their chracteristics
		expects lodBLE : a list of dictionaries defining what to be searched
		returns bleDelegate object
	"""
	cb.set_verbose(True)
	cb.reset()
	Delg = bleDelegate(lodBLE)
	cb.set_central_delegate(Delg)
	cb.scan_for_peripherals()
	logger.info('Waiting for callbacks state=%s' % (cb.get_state()))
	while not Delg.allFound():
		time.sleep(1)
	logger.info('found %d characteristics' % len(Delg.charFound))
	cb.stop_scan()
	return Delg