Skip to content

add BLERadio properties; add name and tx_power to advertisement scan_response #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions adafruit_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
11 changes: 3 additions & 8 deletions adafruit_ble/advertising/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down