diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index 7e12860..3c807a8 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -153,14 +153,16 @@ def start_advertising(self, advertisement, scan_response=None, interval=0.1): Starts advertising the given advertisement. :param buf scan_response: scan response data packet bytes. - ``None`` if no scan response is needed. + If ``None``, a default scan response will be generated that includes + `BLERadio.name` and `BLERadio.tx_power`. :param float interval: advertising interval, in seconds """ - scan_response_data = None - if scan_response: - scan_response_data = bytes(scan_response) + if not scan_response: + scan_response = Advertisement() + scan_response.complete_name = self.name + scan_response.tx_power = self.tx_power self._adapter.start_advertising(bytes(advertisement), - scan_response=scan_response_data, + scan_response=bytes(scan_response), connectable=advertisement.connectable, interval=interval) @@ -235,7 +237,7 @@ def connect(self, advertisement, *, timeout=4): @property def connected(self): - """True if any peers are connected to the adapter.""" + """True if any peers are connected.""" return self._adapter.connected @property @@ -249,3 +251,28 @@ def connections(self): wrapped_connections[i] = self._connection_cache[connection] return tuple(wrapped_connections) + + @property + def name(self): + """The name for this device. Used in advertisements and + as the Device Name in the Generic Access Service, available to a connected peer. + """ + return self._adapter.name + + @name.setter + def name(self, value): + self._adapter.name = value + + @property + def tx_power(self): + """Transmit power, in dBm.""" + return 0 + + @tx_power.setter + def tx_power(self, value): + raise NotImplementedError("setting tx_power not yet implemented") + + @property + def address_bytes(self): + """The device address, as a ``bytes()`` object of length 6.""" + return self._adapter.address.address_bytes diff --git a/adafruit_ble/advertising/__init__.py b/adafruit_ble/advertising/__init__.py index 093d708..558531b 100644 --- a/adafruit_ble/advertising/__init__.py +++ b/adafruit_ble/advertising/__init__.py @@ -220,12 +220,7 @@ class Advertisement: # """Data size in a regular BLE packet.""" def __init__(self): - """Create an advertising packet. - - :param buf data: if not supplied (None), create an empty packet - if supplied, create a packet with supplied data. This is usually used - to parse an existing packet. - """ + """Create an advertising packet.""" self.data_dict = {} self.address = None self._rssi = None @@ -248,8 +243,8 @@ def from_entry(cls, entry): @property def rssi(self): - """Signal strength of the scanned advertisement. Only available on Advertisement's created - from ScanEntrys. (read-only)""" + """Signal strength of the scanned advertisement. Only available on Advertisements returned + from `BLERadio.start_scan()`. (read-only)""" return self._rssi @classmethod