Created
December 3, 2023 11:23
-
-
Save jennifersmith/e398d8493cb2a3f334cfa8c877340fc2 to your computer and use it in GitHub Desktop.
modified example from bumble codebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2021-2022 Google LLC | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# https://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# ----------------------------------------------------------------------------- | |
# Imports | |
# ----------------------------------------------------------------------------- | |
import logging | |
import asyncio | |
import sys | |
import os | |
from bumble.gatt import ( | |
GATT_CHARACTERISTIC_USER_DESCRIPTION_DESCRIPTOR, | |
GATT_DEVICE_INFORMATION_SERVICE, | |
GATT_MANUFACTURER_NAME_STRING_CHARACTERISTIC, | |
Characteristic, | |
Descriptor, | |
Service, | |
) | |
from bumble.device import Device | |
from bumble.host import Host | |
from bumble.controller import Controller | |
from bumble.link import LocalLink | |
from bumble.transport import open_transport_or_link | |
# ----------------------------------------------------------------------------- | |
async def main(): | |
if len(sys.argv) != 4: | |
print( | |
'Usage: run_controller.py <controller-address> <device-config> ' | |
'<transport-spec>' | |
) | |
print( | |
'example: run_controller.py F2:F3:F4:F5:F6:F7 device1.json ' | |
'udp:0.0.0.0:22333,172.16.104.161:22333' | |
) | |
return | |
print('>>> connecting to HCI...') | |
async with await open_transport_or_link(sys.argv[3]) as (hci_source, hci_sink): | |
print('>>> connected') | |
# Create a local link | |
link = LocalLink() | |
# Create a first controller using the packet source/sink as its host interface | |
controller1 = Controller( | |
'C1', host_source=hci_source, host_sink=hci_sink, link=link | |
) | |
controller1.random_address = sys.argv[1] | |
await hci_source.wait_for_termination() | |
# ----------------------------------------------------------------------------- | |
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'DEBUG').upper()) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment