当前位置: 首页>>代码示例>>Python>>正文


Python GATTRequester.connect方法代码示例

本文整理汇总了Python中gattlib.GATTRequester.connect方法的典型用法代码示例。如果您正苦于以下问题:Python GATTRequester.connect方法的具体用法?Python GATTRequester.connect怎么用?Python GATTRequester.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gattlib.GATTRequester的用法示例。


在下文中一共展示了GATTRequester.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ActiveDisconnect

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
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,代码行数:29,代码来源:active_disconnect.py

示例2: AsyncReader

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
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("")
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:31,代码来源:read_async.py

示例3: Reconnect

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
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)
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:30,代码来源:reconnect.py

示例4: SensorTag

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
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.")
开发者ID:shima-nigoro,项目名称:ble_sensor,代码行数:33,代码来源:connect_sync.py

示例5: __init__

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
class MagicBlue:
    def __init__(self, mac_address):
        self.mac_address = mac_address
        self._connection = None

    def connect(self):
        """
        Connect to device
        :return: True if connection succeed, False otherwise
        """
        self._connection = GATTRequester(self.mac_address, False)
        try:
            self._connection.connect(True, "random")
        except RuntimeError as e:
            logger.error('Connection failed : {}'.format(e))
            return False
        return True

    def disconnect(self):
        """
        Disconnect from device
        """
        self._connection.disconnect()

    def is_connected(self):
        """
        :return: True if connection succeed, False otherwise
        """
        return self._connection.is_connected()

    def set_color(self, rgb_color):
        """
        Change bulb's color
        :param rgb_color: color as a list of 3 values between 0 and 255
        """
        self._connection.write_by_handle(HANDLE_CHANGE_COLOR, bytes(bytearray([MAGIC_CHANGE_COLOR] + list(rgb_color))))

    def set_random_color(self):
        """
        Change bulb's color with a random color
        """
        self.set_color([random.randint(1, 255) for i in range(3)])

    def turn_off(self):
        """
        Turn off the light by setting color to black (rgb(0,0,0))
        """
        self.set_color([0, 0, 0])

    def turn_on(self, brightness=1.0):
        """
        Set white color on the light
        :param brightness: a float value between 0.0 and 1.0 defining the brightness
        """
        self.set_color([int(255 * brightness) for i in range(3)])
开发者ID:b0tting,项目名称:magicblue,代码行数:57,代码来源:magicbluelib.py

示例6: JustConnect

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
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!")
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:13,代码来源:connect.py

示例7: Reader

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
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
开发者ID:DnPlas,项目名称:EdisonBLE,代码行数:17,代码来源:blu_led.py

示例8: Reader

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
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])))
开发者ID:kived,项目名称:pygattlib-tmp,代码行数:17,代码来源:write.py

示例9: connect

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
def connect(deviceaddr):
    """
    Attempt a connection to the target device - notoriously unreliable due to driver issues and the ephemeral nature of BTLE
    """

    deviceHandle = GATTRequester(deviceaddr, False, args.listen_interface)
    flag = 0
    device = None

    while flag<5:
        try:
            #bool wait,std::string channel_type, std::string security_level, int psm, int mtu)
            deviceHandle.connect(True, 'public','low')
            break
        except Exception,e:
            # We have a bunch of RuntimeErrors raised for various reasons by the GATTLib library -- lets handle those, then maybe fork GATTLib and get those to be more specific
            if type(e) == RuntimeError:
                
                if e.message == "Channel or attrib not ready":
                    if deviceHandle.is_connected():
                        if args.debug == True: print "Device error"
                    break # i don't think we can win
                    #print 'w'
                    #pdb.set_trace()
                    #TODO: maybe see if it's connected or not?
                    #flag += 1 # we don't want to get stuck here.
                    #continue

                elif e.message == "Already connecting or connected":
                    if deviceHandle.is_connected():
                        break
                    else:
                        time.sleep(3)
                        if args.debug == True: print '\t Waiting for response to connection...'
                    continue

                else:
                    #errnum = int(e.message.split()[-1][1:-1]) #remove the ( and ) from the error number
                    time.sleep(1)
                    if args.debug == True: print '!!!' + e.message
                    continue

            print e
            flag += 1
开发者ID:Department13,项目名称:BlueDriver,代码行数:46,代码来源:scan.py

示例10: Reader

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
class Reader(object):
    def __init__(self, address):
        self.requester = GATTRequester(address, False)
        self.connect()
        self.request_data()

    def connect(self):
        print("Connecting...", end=' ')
        sys.stdout.flush()

        self.requester.connect(True)
        print("OK!")

    def request_data(self):
        data = self.requester.read_by_handle(0x1)[0]

        print("bytes received:", end=' ')
        for b in data:
            print(hex(ord(b)), end=' ')
        print("")
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:22,代码来源:read.py

示例11: AsyncReader

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
class AsyncReader(object):
    def __init__(self, address):
        self.requester = GATTRequester(address, False)
        self.response = NotifyMeYourValue()

        self.connect()
        self.request_data()
        self.loop()

    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 loop(self):
        while not self.response.done:
            time.sleep(0.1)
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:24,代码来源:read_callback.py

示例12: PassiveDisconnect

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
class PassiveDisconnect(object):
    def __init__(self, address):
        self.requester = GATTRequester(address, False)

        self.connect()
        self.wait_disconnection()

    def connect(self):
        print("Connecting...", end=' ')
        sys.stdout.flush()

        self.requester.connect(True)
        print("OK!")

    def wait_disconnection(self):
        status = "connected" if self.requester.is_connected() else "not connected"
        print("Checking current status: {}".format(status))
        print("\nNow, force a hardware disconnect. To do so, please switch off,\n"
              "reboot or move away your device. Don't worry, I'll wait...")

        while self.requester.is_connected():
            time.sleep(1)

        print("\nOK. Current state is disconnected. Congratulations ;)")
开发者ID:AwxiVYTHUIiMOol,项目名称:https-bitbucket.org-OscarAcena-pygattlib,代码行数:26,代码来源:passive_disconnect.py

示例13: GATTRequester

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
from gattlib import GATTRequester

req = GATTRequester("C9:E8:56:3B:4D:B1", False)
req.connect(True, "random")
req.is_connected()

print(req.discover_primary())
req.disconnect()
开发者ID:Habasari,项目名称:bleep,代码行数:10,代码来源:test_gattlib.py

示例14: Copyright

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
#!/usr/bin/python
# -*- mode: python; coding: utf-8 -*-

# Copyright (C) 2014, Oscar Acena <[email protected]>
# This software is under the terms of Apache License v2 or later.

from __future__ import print_function

import sys
from gattlib import GATTRequester

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: {} <addr>".format(sys.argv[0]))
        sys.exit(1)

    requester = GATTRequester(sys.argv[1], False)

    print("Connecting...")
    sys.stdout.flush()
    requester.connect(True)

    primary = requester.discover_primary()
    for prim in primary:
        print(prim)

    print("Done.")
开发者ID:kived,项目名称:pygattlib-tmp,代码行数:29,代码来源:discover_primary.py

示例15: post

# 需要导入模块: from gattlib import GATTRequester [as 别名]
# 或者: from gattlib.GATTRequester import connect [as 别名]
}

def post(host, data):
    r = requests.post("http://{}:{}/{}".format(host["ip"], host["port"], host["endpoint"]), data=data)
    print r.status_code, r.reason, r.text
    return r.text

service = DiscoveryService()
devices = service.discover(2)

for addr, name in devices.items():
	print("%s (%s)" % (name,addr))
	print(name)
	if(name=="RapidPrototype"):
		req=GATTRequester(addr,False)
		req.connect(True)
		status="connected" if req.is_connected() else "not connectd"
		print(status)
		prevData="00"
		while(True):
			data=req.read_by_uuid("A495FF21-C5B1-4B44-B512-1370F02D74DE")
			data=str(data)
			data=data[4:6]
			if(data=="00" and prevData=="01"):
				print("Box is open")
				val = {
                                        "sensor_id": "pillbox",
                                        "value": 0
                                }
				post(host, val)
			if(data=="01" and prevData=="00"):
开发者ID:PseudoSky,项目名称:rpcs-sensors,代码行数:33,代码来源:blex.py


注:本文中的gattlib.GATTRequester.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。