目标
我有一个HITSLAM摄像头关闭蓝牙按钮 (这是一个AB Shutter 3设备,一个普通的蓝牙摄像头遥控器),我想连接到我的NVIDIA使用蓝牙,以便我可以使用按钮的输入进行一些任务。
我所做的
我正在使用PyBluez库进行连接。我使用以下方法查找AB Shutter 3使用的端口和协议(其中target_device_address是AB Shutter 3的设备地址):
service_matches = bt.find_service(name=None,uuid=None,address=target_device_address)
first_match = service_matches[0]
print("Port {}, Name {}, Host {}, Protocol {}".format(first_match['port'], first_match['name'], first_match['host'], first_match['protocol']))这就是我如何获得连接到的端口(17)和它使用的协议(L2CAP)。
现在,我尝试使用以下方法连接到它:
client_sock = bt.BluetoothSocket(bt.L2CAP)
client_sock.connect((target_device_address,port))我还使用了Python的本机socket库(获得了相同的结果):
client_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_L2CAP)
client_sock.connect((target_device_address,port))它成功地连接到了hcitool,在此之后,我等待用户输入:
if target_device_address in (subprocess.getoutput("hcitool con")).split():
print('connected')
while True:
data = client_sock.recv(1024)
print(str(data))问题
/dev/input/中并不显示为输入。当我通过GUI手动连接它时,它会显示为/dev/input/event5。我的问题
hcitool con,它是如何连接的,但还没有注册为输入设备(并注册任何输入)?bluetoothctl,但是它对我来说没有意义,为什么Python不能建立这个连接并检索信息。发布于 2021-02-26 07:23:57
我的建议是不要使用hcitool,因为早在2017年,它就是已弃用。
我更喜欢直接使用BlueZ D-Bus API,这是在:https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/device-api.txt中记录的。
这可以在Python中使用吡咯烷酮库进行访问。
我将假设您的蓝牙适配器位于Jetson上的hci0上,但您可以使用以下方法进行检查:
$ busctl tree org.bluez
└─/org
└─/org/bluez
└─/org/bluez/hci0这将使代码类似于:
import pydbus
DEVICE_ADDR = '11:22:22:E7:CE:BE'
# DBus object paths
BLUEZ_SERVICE = 'org.bluez'
ADAPTER_PATH = '/org/bluez/hci0'
device_path = f"{ADAPTER_PATH}/dev_{DEVICE_ADDR.upper().replace(':', '_')}"
# setup dbus
bus = pydbus.SystemBus()
mngr = bus.get(BLUEZ_SERVICE, '/')
adapter = bus.get(BLUEZ_SERVICE, ADAPTER_PATH)
device = bus.get(BLUEZ_SERVICE, device_path)
device.Connect()这应该在/dev/input/上创建事件,我将使用python库埃夫德夫获取输入,就像在下面的问题中所做的那样:
https://stackoverflow.com/questions/66379600
复制相似问题