bluez交叉编译到Arm后,按照
hciconfig hci0 up
hciconfig hci0 iscan
启动蓝牙后,想进行SPP通讯,结果一直找不到channel。
问题:执行 sdptool add --channel=1 SP增加频道后,运行sdptool browse local发现出现异常:
Failed to connect to SDP server on FF:FF:FF:00:00:00: No such file or directory。
解决:在网上查了看有说是bluez版本问题,我换了bluez-4.101重新编译,还是这个问题。后来比照了linux下的运行环境 /etc/init.d/bluetooth里发现需要启动bluetoothd。
执行bluetoothd -n -u 出现问题:D-Bus setup failed: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory,
然后查了下需要执行dbus-daemon --system,
出现了异常1:Failed to start message bus: Failed to open "/usr/bluez/etc/dbus-1/system.conf": No such file or directory,将编译的文件system.conf拷到对应位置
2:Failed to start message bus: Could not get UID and GID for username "messagebus",在/etc/passwd 加入mesagebus, messagebus:x:102:106::/var/run/dbus:/bin/false
3:mkdir -p /usr/bluez/var/run/dbus/
dbus-daemon --system 执行成功后,将生成的system_bus_socket复制过去 ln -s /usr/bluez/var/run/dbus/system_bus_socket /var/run/dbus/system_bus_socket
bluetoothd -n -u 执行成功,然后sdptool browse local执行成功,问题解决。
总结:需要执行dbus-daemon --system 启动bluetoothd -n -u
SPP协议通讯的C++实现代码:可以参考文档Bluetooth for Programmers.pdf