本文整理汇总了Python中gattlib.GATTRequester类的典型用法代码示例。如果您正苦于以下问题:Python GATTRequester类的具体用法?Python GATTRequester怎么用?Python GATTRequester使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GATTRequester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, addr=None, device='hci0', debug=False, **connect_kwargs):
'''
@param addr (optional): MAC address of Pavlok device
If not passed, will be discovered with DiscoveryService (requires root privileges)
@param device (optional): host Bluetooth interface ('hci0' by default)
@param debug (optional): debug logging (disabled by default)
@param connect_kwargs: keyword arguments (security_level, channel_type, mtu, psm) to pass to GATTRequester.connect
security_level: 'low' (default), 'medium', 'high'
channel_type: 'public' (default), 'random'
mtu: integer
psm: integer
'''
self._init_logging(debug)
if not addr:
addr = self._get_pavlok_mac_addr(device)
assert addr, 'Could not find Pavlok device'
GATTRequester.__init__(self, addr, False, device) #GATTRequester is an old-style class
if connect_kwargs:
self.logger.debug('Got keyword arguments for self.connect: %s', connect_kwargs)
self.connect(wait=False, **connect_kwargs) #Blocking connect() is better, but it would require root privileges
self._wait_until_connected()
characteristics = self.discover_characteristics()
self.logger.debug('GATT characteristics: %s', characteristics)
#Find matching value handles for service UUIDs
self.handles = {name:filter(lambda e: e['uuid'] == uuid, characteristics)[0]['value_handle']\
for name, uuid in self.service_uuids.items()}
self.logger.debug('GATT value handles: %s', self.handles)
self.logger.debug('Hardware revision: %s, firmware revision: %s', self.hardware_revision, self.firmware_revision)
示例2: Reconnect
class Reconnect(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
times = 3
print("I will connect & disconnect {} times...".format(times))
for i in range(times):
self.connect()
self.disconnect()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
time.sleep(1)
def disconnect(self):
print("Disconnecting...", end=' ')
sys.stdout.flush()
self.requester.disconnect()
print("OK!")
time.sleep(1)
示例3: ActiveDisconnect
class ActiveDisconnect(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.connect()
self.check_status()
self.disconnect()
self.check_status()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
def check_status(self):
status = "connected" if self.requester.is_connected() else "not connected"
print("Checking current status: {}".format(status))
time.sleep(1)
def disconnect(self):
print("Disconnecting...", end=' ')
sys.stdout.flush()
self.requester.disconnect()
print("OK!")
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:27,代码来源:active_disconnect.py
示例4: AsyncReader
class AsyncReader(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.response = GATTResponse()
self.connect()
self.request_data()
self.wait_response()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
def request_data(self):
self.requester.read_by_handle_async(0x1, self.response)
def wait_response(self):
while not self.response.received():
time.sleep(0.1)
data = self.response.received()[0]
print("bytes received:", end=' ')
for b in data:
print(hex(ord(b)), end=' ')
print("")
示例5: __init__
def __init__(self, wakeup, pstream, tstream, *args):
GATTRequester.__init__(self, *args)
self.wakeup = wakeup
self.s = pstream
self.t = tstream
self.count = 0
self.prev_ay = 1
self.local_maxima = 1
示例6: JustConnect
class JustConnect(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.connect()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
示例7: createRequester
def createRequester(self):
"""Create a GATTRequester for the BLEConnectionManager
:return: Returns the newly created requester
:rtype: GATTRequester
"""
if self.adapter == "":
self.requester = GATTRequester(self.address, False)
else:
self.requester = GATTRequester(self.address, False, self.adapter)
return self.requester
示例8: OnGSRButtonClick
def OnGSRButtonClick(self):
req = GATTRequester("98:4F:EE:0F:59:D6")
temp = []
f = open("gsr.csv", 'a')
writer = csv.writer(f)
writer.writerow( ('timestamp', 'gsr') )
flagTemp = 0;
flagBP = 1;
flagGSR = 0;
req.write_by_handle(0x000e,str(bytearray([01])))
tt = req.read_by_handle(0x0010)[0]
示例9: Reader
class Reader(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.connect()
self.send_data()
def connect(self):
print("Connecting...", end=" ")
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
def send_data(self):
self.requester.write_by_handle(0x2E, str(bytearray([2])))
示例10: Reader
class Reader(object):
def __init__(self, address):
self.requester = GATTRequester(address , False)
self.connect()
self.send_data()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
def send_data(self):
self.requester.write_by_handle(0xb, str(bytearray([1]))) # You can find the bluetooth handle using
示例11: __init__
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.response = NotifyMeYourValue()
self.connect()
self.request_data()
self.loop()
示例12: __init__
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.connect()
self.check_status()
self.disconnect()
self.check_status()
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:7,代码来源:active_disconnect.py
示例13: __init__
def __init__(self, address):
self.requester = GATTRequester(address, False)
self.response = GATTResponse()
self.connect()
self.request_data()
self.wait_response()
示例14: SensorTag
class SensorTag(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
def connect(self):
print("Connecting...")
self.requester.connect(True)
print("Succeed.")
def check_status(self):
status = "connected" if self.requester.is_connected() else "not connected"
print("Checking current status: {}".format(status))
def disconnect(self):
print("Disconnecting...")
self.requester.disconnect()
print("Succeed.")
def show_primary(self):
print("Discover Primary...")
primary = self.requester.discover_primary()
for prim in primary:
print(prim)
print("Done.")
def show_characteristic(self):
print("Discover Characteristic...")
characteristic = self.requester.discover_characteristics()
for char in characteristic:
print(char)
print("Done.")
示例15: __init__
def __init__(self, address):
self.requester = GATTRequester(address, False)
times = 3
print("I will connect & disconnect {} times...".format(times))
for i in range(times):
self.connect()
self.disconnect()