示例#1
0
def main():
    # io_callbacks must be called before `ble.config` to enable
    # Require MITM.
    ble.io_callbacks(display_cb=display_cb,
                     request_cb=request_cb,
                     confirm_cb=confirm_cb)
    ble.config(security=ble.PAIRING_REQUIRE_MITM)
    # Comment the line above, and uncomment the line below to use
    # bonding. Once bonded the pairing activity will no longer be
    # necessary on each connection as long as the keys are retained by
    # the devices.
    # ble.config(security=ble.PAIRING_REQUIRE_MITM | ble.PAIRING_REQUIRE_BONDING)

    print("Connecting")
    conn = ble.gap_connect(address_type, address)
    print("Connected")

    # The delay is not necessary, just here to easily observe the
    # secured vs unsecured state.
    print("Wait for a bit before securing")
    time.sleep(5)

    print("Securing")
    conn.secure(secure_cb)

    print("Sleep forever")
    while True:
        time.sleep(1)
示例#2
0
def main():
    conn = ble.gap_connect(ble.ADDR_TYPE_PUBLIC, unhexlify(ADDRESS))
    xbeeconn = ble.xbee_connect(conn, process_frame, PASSWORD, timeout=10)

    while True:
        print("Querying DT & TP")
        xbeeconn.send(DT_request)
        xbeeconn.send(TP_request)
        time.sleep(5)
示例#3
0
 def connect(self):
     if self.address is None:
         self.address = self._find_thunderboard()
     if self.conn is None:
         if self.address is not None:
             try:
                 print("Attempting connection to: {}".format(self.address))
                 self.conn = ble.gap_connect(ble.ADDR_TYPE_PUBLIC, self.address)
                 self.leds_characteristic = self.get_characteristics_from_uuids(io_service_uuid,
                                                                                io_characteristic_uuid)[1]
                 self.lumens_characteristic = self.get_characteristics_from_uuids(env_service_uuid,
                                                                                  lumens_characteristic_uuid)[0]
                 print("connected")
             except OSError:
                 self.conn = None
示例#4
0
import binascii
from digi import ble

# Change these two variables to your device's address and address type.
# The address and address type can be discovered using ble.gap_scan().
REMOTE_ADDRESS = "00:0B:57:28:65:D0"
address_type = ble.ADDR_TYPE_PUBLIC

# Put address into bytes (without colons)
address = binascii.unhexlify(REMOTE_ADDRESS.replace(':', ''))

ble.active(True)
print("Attempting connection to:", REMOTE_ADDRESS)

# Context manager will automatically close() the connection upon completion
with ble.gap_connect(address_type, address) as conn:
    print("Connected")

    print("Discovering services...")
    for service in conn.gattc_services():
        print("Service", service)

    print("Configuring timing parameters to use a slower connection...")
    conn.config(interval_ms=1000, timeout_ms=10000)

    print("Discovering services again...")
    for service in conn.gattc_services():
        print("Service", service)

print("Done")