如何扫描蓝牙设备

来自百问网嵌入式Linux wiki
跳转至: 导航搜索

如何扫描蓝牙设备

扫描可用的蓝牙设备

	Board $> hcitool scan
	Scanning ...
	       A0:AF:BD:3B:26:61       lmecxl0923
	       B0:55:08:40:33:84       HUAWEI P8 lite 2017

将设备设置为可见

设置我们的蓝牙设备对其他蓝牙设备的可见性。
启用可见性:
		Board $> hciconfig hciX piscan
(hciX对应于可用的蓝牙硬件:hci0)
禁用可见性:
		Board $> hciconfig hciX noscan
(hciX对应于可用的蓝牙硬件:hci0)

如何通过蓝牙/系统扫描

Systemd 提供了用于蓝牙管理的工具:bluetoothctl。
使用蓝牙进行扫描、配对和连接的示例会话过程:
	Board $> bluetoothctl
	[NEW] Controller 43:43:A1:12:1F:AC stm32mp1 [default]
	Agent registered
	[bluetooth]# power on
	Changing power on succeeded
	[CHG] Controller 43:43:A1:12:1F:AC Powered: yes
	[bluetooth]# agent on
	Agent is already registered
	[bluetooth]# default-agent
	Default agent request successful
	[bluetooth]# scan on
	Discovery started
	[CHG] Controller 43:43:A1:12:1F:AC Discovering: yes
	[NEW] Device D8:DB:36:D1:39:88 STM
	...
	[bluetooth]# scan off
	[CHG] Controller 43:43:A1:12:1F:AC Discovering: no
	Discovery stopped
	[bluetooth]#pair D8:DB:36:D1:39:88
	Pairing successful
	[bluetooth]# connect D8:DB:36:D1:39:88
	Connection successful
	[STM]# quit
	Agent unregistered
	[DEL] Controller 43:43:A1:12:1F:AC stm32mp1 [default]