[英]How to specify AdressType in bluez device-api?
我正在嘗試通過 python 腳本將 LE 設備連接到我的 Linux 筆記本電腦。 盡管如此,必須將設備地址指定為“隨機”才能進行連接,我的示例(主要是https://www.bluetooth.com/blog/the-bluetooth-for-linux-developers-study- guide/ ) 沒有顯示任何方法。
BlueZ 的 device-api ( https://github.com/bluez/bluez/blob/master/doc/device-api.txt ) 將其列為其屬性之一,但我的知識仍然不完整,我不能'無法設法找到設置此屬性的方法。
任何想法、指示或示例都將非常有幫助。
以下是我的腳本
PATH_DA_BSN = "/org/bluez/hci0/dev_CA_DB_17_8A_02_97"
ADAPTER_NAME = "hci0"
BLUEZ_SERVICE_NAME = "org.bluez"
BLUEZ_NAMESPACE = "/org/bluez/"
DEVICE_INTERFACE = BLUEZ_SERVICE_NAME + ".Device1"
ADAPTER_INTERFACE = BLUEZ_SERVICE_NAME + ".Adapter1"
def connect():
global bus
global device_interface
try:
device_interface.Connect()
except Exception as e:
print("Failed to connect")
print(e.get_dbus_name())
print(e.get_dbus_message())
if ("UnknownObject" in e.get_dbus_name()):
print("Try scanning first to resolve this problem")
return bluetooth_constants.RESULT_EXCEPTION
else:
print("Connected OK")
return bluetooth_constants.RESULT_OK
bus = dbus.SystemBus()
bsn_proxy = bus.get_object(BLUEZ_SERVICE_NAME, PATH_DA_BSN)
device_interface = dbus.Interface(bsn_proxy, DEVICE_INTERFACE)
adapter_path = BLUEZ_NAMESPACE + ADAPTER_NAME
# acquire the adapter interface so we can call its methods
adapter_object = bus.get_object(BLUEZ_SERVICE_NAME, adapter_path)
adapter_interface = dbus.Interface(adapter_object, ADAPTER_INTERFACE)
print("Connecting to " + PATH_DA_BSN)
connect()
AddressType
已在發現設備時設置。
您可以使用 D-Bus 的GetManagedObjects
功能遍歷已發現的設備,以查找為每個設備設置的地址類型。
使用pydbus綁定的示例:
>>> import pydbus
>>> bus = pydbus.SystemBus()
>>> mngr = bus.get('org.bluez', '/')
>>> mngd_objs = mngr.GetManagedObjects()
>>> for path, iface in mngd_objs.items():
... if 'org.bluez.Device1' in iface.keys():
... print(iface.get('org.bluez.Device1', {}).get('AddressType'))
...
public
random
random
public
public
public
random
public
public
public
random
你有兩個選擇:
我推薦選項 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.