Skip to content
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

Decrease default Advertisement interval from 1200 to 100 ms #111

Merged
merged 1 commit into from
Aug 18, 2023
Merged
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
31 changes: 30 additions & 1 deletion bless/backends/bluezdbus/dbus/advertisement.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class BlueZLEAdvertisement(ServiceInterface):
org.bluez.LEAdvertisement1 interface implementation

https://github.com/bluez/bluez/blob/5.64/doc/advertising-api.txt
https://python-dbus-next.readthedocs.io/en/latest/type-system/index.html
https://elixir.bootlin.com/linux/v5.11/source/include/net/bluetooth/mgmt.h#L794
https://github.com/bluez/bluez/issues/527
https://patches.linaro.org/project/linux-bluetooth/list/?series=31700
"""

interface_name: str = "org.bluez.LEAdvertisement1"
Expand Down Expand Up @@ -50,7 +54,16 @@ def __init__(
self._solicit_uuids: List[str] = [""]
self._service_data: Dict = {}

self._tx_power: int = 20
# 3 options below are classified as Experimental in BlueZ and really work only:
# - when BlueZ is compiled with such option (usually it is)
# - and when "bluetoothd" daemon is started with -E, --experimental option (usually it's not)
# They are taken into account only with Kernel v5.11+ and BlueZ v5.65+.
# It's a known fact that BlueZ verions 5.63-5.64 have broken Dbus part for LEAdvertisingManager
# and do not work properly when the Experimental mode is enabled.
self._min_interval: int = 100 # in ms, range [20ms, 10,485s]
self._max_interval: int = 100 # in ms, range [20ms, 10,485s]
self._tx_power: int = 20 # range [-127 to +20]

self._local_name = app.app_name

self.data = None
Expand Down Expand Up @@ -116,6 +129,22 @@ def TxPower(self) -> "n": # type: ignore # noqa: F821 N802
def TxPower(self, dbm: "n"): # type: ignore # noqa: F821 N802
self._tx_power = dbm

@dbus_property()
def MaxInterval(self) -> "u": # type: ignore # noqa: F821 N802
return self._max_interval

@MaxInterval.setter # type: ignore
def MaxInterval(self, interval: "u"): # type: ignore # noqa: F821 N802
self._max_interval = interval

@dbus_property()
def MinInterval(self) -> "u": # type: ignore # noqa: F821 N802
return self._min_interval

@MinInterval.setter # type: ignore
def MinInterval(self, interval: "u"): # type: ignore # noqa: F821 N802
self._min_interval = interval

@dbus_property()
def LocalName(self) -> "s": # type: ignore # noqa: F821 N802
return self._local_name
Expand Down