Merge pull request #51 from mogenson/mogenson/console-py-rand-addr

Use random address in console.py if device config is not provided
This commit is contained in:
Michael Mogenson
2022-10-24 09:15:10 -04:00
committed by GitHub

View File

@@ -20,14 +20,14 @@
# Imports # Imports
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
import asyncio import asyncio
from bumble.hci import HCI_Constant
import os
import os.path
import logging import logging
import click import os
from collections import OrderedDict import random
import colors
import re import re
from collections import OrderedDict
import click
import colors
from bumble.core import UUID, AdvertisingData, TimeoutError, BT_LE_TRANSPORT from bumble.core import UUID, AdvertisingData, TimeoutError, BT_LE_TRANSPORT
from bumble.device import ConnectionParametersPreferences, Device, Connection, Peer from bumble.device import ConnectionParametersPreferences, Device, Connection, Peer
@@ -35,6 +35,7 @@ from bumble.utils import AsyncRunner
from bumble.transport import open_transport_or_link from bumble.transport import open_transport_or_link
from bumble.gatt import Characteristic from bumble.gatt import Characteristic
from bumble.hci import ( from bumble.hci import (
HCI_Constant,
HCI_LE_1M_PHY, HCI_LE_1M_PHY,
HCI_LE_2M_PHY, HCI_LE_2M_PHY,
HCI_LE_CODED_PHY, HCI_LE_CODED_PHY,
@@ -272,7 +273,11 @@ class ConsoleApp:
if device_config: if device_config:
self.device = Device.from_config_file_with_hci(device_config, hci_source, hci_sink) self.device = Device.from_config_file_with_hci(device_config, hci_source, hci_sink)
else: else:
self.device = Device.with_hci('Bumble', 'F0:F1:F2:F3:F4:F5', hci_source, hci_sink) random_address = f"{random.randint(192,255):02X}" # address is static random
for c in random.sample(range(255), 5):
random_address += f":{c:02X}"
self.append_to_log(f"Setting random address: {random_address}")
self.device = Device.with_hci('Bumble', random_address, hci_source, hci_sink)
self.device.listener = DeviceListener(self) self.device.listener = DeviceListener(self)
await self.device.power_on() await self.device.power_on()