我正在尝试使用CoreBluetooth(蓝牙4.0)通过iPhone连接到Raspberry Pi.我发现了设备并使用以下代码发送连接请求:
if (peripheral != self.foundPeripheral) {
NSLog(@"Try to connect to %@", peripheral.name);
self.foundPeripheral = peripheral;
[self.centralManager stopScan];
[self.centralManager connectPeripheral:peripheral options:nil];
}
Run Code Online (Sandbox Code Playgroud)
didConnectPeripheral或didFailedToConnectPeripheral都不会被调用.我还确保将RPi用于宣传蓝牙低功耗
sudo hciconfig hci0 leadv
Run Code Online (Sandbox Code Playgroud)
但是当我检查活动连接时
hcitool con
Run Code Online (Sandbox Code Playgroud)
没有活动的连接.我错过了为RPi设置的一些设置吗?外围设备上的名称变量也是空白的,是因为我还没有连接吗?
我正在尝试创建一些脚本来发现并在嵌入式arch linux平台上配对蓝牙设备,似乎无法得到任何对dbus-send命令的回复.
错误消息几乎总是相同(方法不存在),但是发送的语法似乎是正确的.
我在谷歌搜索并搜索了正确的语法和错误,但一直找不到任何解决方案.
[root@alarmpi ~]# dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.GetProperties
Error org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with signature "" on interface "org.bluez.Manager" doesn't exist
[root@alarmpi ~]# dbus-send --system --print-reply --dest=org.bluez /org/bluez/134/hci0 org.bluez.Adapter.GetProperties
Error org.freedesktop.DBus.Error.UnknownObject: Method "GetProperties" with signature "" on interface "org.bluez.Adapter" doesn't exist
Run Code Online (Sandbox Code Playgroud)
Bluez已经安装,我可以使用hcitool和bluetoothctl实用程序来手动发现和配对设备,但是这种方法对最终用户来说是行不通的,我需要为他们创建一个Web界面来执行发现和配对.
似乎dbus是执行此操作的首选方法,因为bluetoothctl不接受命令行参数以允许它配对设备地址.
任何帮助/建议将不胜感激.
我目前正在尝试由RadiusNetworks发布的Raspberry Pi iBeacon教程
http://developer.radiusnetworks.com/2013/10/09/how-to-make-an-ibeacon-out-of-a-raspberry-pi.html
但几秒后我的连接超时有问题.我已经完成了一个新的raspbian构建,并尝试了2个不同的加密狗(AZIO V400和IOGEAR GBU521),我已经尝试使用Bluez 5.8的教程以及Bluez 5.11,两者都在新的Raspbian加载.
当我调用启动脚本时,我看到:
pi@piBlueTest ~ $ ./start
Launching virtual iBeacon...
LE set advertise enable on hci0 returned status 12
< HCI Command: ogf 0x08, ocf 0x0008, plen 44
1E 02 01 1A 1A FF 4C 00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60
D0 F5 A7 10 96 E0 00 00 00 00 C9 00 00 00 00 00 00 00 00 00
00 00 00 00
> …
Run Code Online (Sandbox Code Playgroud) syslogd的
在执行/ libexec/bluetooth/bluetoothd --plugin = time -d -E -n时,错误"没有足够的免费句柄来注册服务"发生如下:
bluetoothd [756]:src/adapter.c:clear_uuids()为索引0发送清除uuids命令
bluetoothd [756]:src/adapter.c:set_mode()发送索引0的set mode命令
bluetoothd [756]:src/gatt -database.c:btd_gatt_database_new()GATT Manager注册适配器:/ org/bluez/hci0
bluetoothd [756]:src/adapter.c:adapter_service_add()/ org/bluez/hci0
bluetoothd [756]:src/sdpd-service .c:add_record_to_server()使用句柄0x10002添加记录
bluetoothd [756]:src/sdpd-service.c:add_record_to_server()记录模式UUID 00000007-0000-1000-8000-00805f9
bluetoothd [756]:src/sdpd-service. c:add_record_to_server()记录模式UUID 00000100-0000-1000-8000-00805f9
bluetoothd [756]:src/sdpd-service.c:add_record_to_server()记录模式UUID 00001002-0000-1000-8000-00805f9
bluetoothd [756]: src/sdpd-service.c:add_record_to_server()记录模式UUID 00001800-0000-1000-8000-00805f9
bluetoothd [756]:src/adapter.c:adapter_service_insert()/ org/bluez/hci0
bluetoothd [756]:src/adapter.c:add_uuid()se nding为索引0添加uuid命令
bluetoothd [756]:src/gatt-database.c:gatt_db_service_added()GATT服务添加到本地数据库
bluetoothd [756]:无法获取"Service Changed"特性的句柄
bluetoothd [756]:src /adapter.c:adapter_service_add()/ org/bluez/hci0
bluetoothd [756]:src/sdpd-service.c:add_record_to_server()用句柄0x10003
bluetoothd 添加记录[756]:src/sdpd-service.c:add_record_to_server( )记录模式UUID 00000007-0000-1000-8000-00805f9
bluetoothd [756]:src/sdpd-service.c:add_record_to_server()记录模式UUID 00000100-0000-1000-8000-00805f9
bluetoothd [756]:src/sdpd- …
我正在尝试编写一个搜索附近蓝牙设备并与之通信的应用程序.我的应用程序将用C++编写,并且打算在Linux下运行.
4年前,我使用了BlueZ.但是现在,正如我所看到的,API已经发生了很大变化,现在它正在使用D-Bus.我对D-Bus没有经验.我查看了一些与客户端/服务器模型相关的教程.现在,我很喜欢D-Bus.
但我找不到任何解释如何将BlueZ与D-Bus一起使用的例子.我需要一些使用BlueZ和D-Bus的指导.
在C或C++中是否有通过D-Bus使用BlueZ的教程或示例?
(注意:已经用Google搜索了)
我有一个设备有一些自定义GATT服务,我想编写一个Linux程序来与它进行交互.经过一番搜索,我发现Linux正在使用BlueZ来处理蓝牙LE协议.我正在使用UZntu 15.10和BlueZ 5.35,但我无法弄清楚如何在用户空间程序中使用这个BlueZ.我无法在任何地方找到API文档,没有教程,示例,什么都没有.甚至可以使用这个BlueZ堆栈来做除了使用默认服务连接蓝牙设备之外的任何事情吗?如果是这样,文档在哪里?(最好是C/C++ API,但此时一切顺利)
我正在运行运行Ubuntu和Python 2.7的家用计算机进行测试,希望Raspberry Pi 3能够使用具有自定义服务和特性的BLE进行广告宣传.我在两台设备上都安装了Bluez版本5.42(使用推荐的方法)以及dbus-python.我的计算机和Raspberry Pi都可以使用hci0 lescan 0
命令进行广告,但是我想用bluez示例脚本做广告,例如在这里找到example-gatt-client.py和example-advertisement.py ,因为我想用我自己的自定义特征.
家用电脑 - 内核版本4.4.0-31通用
我可以通过运行example-gatt-server.py和example-advertise.py来创建自定义特征和广告,而我的家用计算机上没有任何问题.我遇到的一个障碍是我需要通过添加--experimental
到位于的bluetooth.service文件来启用Bluez实验模式/lib/systemd/system/bluetooth.service
.另外安装dbus-python库有点痛苦,因为我必须自己为Python2构建和安装它.
advertise.py脚本查找名为"org.bluez.LEAdvertisingManager1"的特定广告界面.gatt-server.py脚本查找"org.bluez.GattManager1".我可以通过运行以下命令来检查该接口是否存在:
dbus-send --system --dest=org.bluez --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects
Run Code Online (Sandbox Code Playgroud)
在家用计算机上找到这些接口并正常工作.脚本运行没有问题.
Raspberry Pi - 内核版本4.4.38-v7 +
使用相同的bluez版本和实验性功能,我在尝试运行advertise.py时遇到此错误:
找不到LEAdvertisingManager1接口.
当我执行命令"systemctl status bluetooth"时,它显示实验标志已启用,但我在运行时看不到LEAdvertistingManager1.
dbus-send --system --dest=org.bluez --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects
Run Code Online (Sandbox Code Playgroud)
然而,我可以运行gatt-server.py脚本而不会发出任何问题,这意味着找到了"org.bluez.GattManager1"并且工作正常.我在这里错过了什么?
我已经搜索了这个问题,但唯一的建议是启用实验性功能并确保我的内核> = 4.1.
我正在使用QN9021
SoC controller mode
(BLE蓝牙核心规范v4.0).它支持一些标准HCI
命令以及一些供应商特定命令.我想把它贴在我的ubuntu
笔记本电脑上.
我使用的命令是hciattach
.
hciattach -s 9600 /dev/ttyUSBx any 9600 noflow nosleep
Run Code Online (Sandbox Code Playgroud)
hcidump
执行时的节目sudo hciconfig hci1 up
.
HCI sniffer - Bluetooth packet analyzer ver 5.37
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Command Complete (0x0e) plen 12
Read Local Supported Features (0x04|0x0003) ncmd 11
status 0x00
Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Complete (0x0e) plen 12
Read Local Version Information …
Run Code Online (Sandbox Code Playgroud) 我正在使用 python 开发一个 Linux 应用程序,它将连接到我的 BLE 设备并通过通知特性获取数据。我正在使用pygatt进行 BLE 通信。我可以成功连接并绑定到设备并读取/写入特性。即使我可以订阅通知特性,但问题是,我的 BLE 设备是一台定制机器,里面有 4 个计数器,每次计数器的数据发生变化时,它都会设置相应的通知标志,因此,使用 onDataChanged-像我可以从读取特性中读取计数器数据的方法。在使用 pygatt 的 Python 中,我可以订阅通知特性:
class_name.device.subscribe(uuid.UUID(notify_characteristic),callback=notifyBle)
Run Code Online (Sandbox Code Playgroud)
和 notifyBle 是:
def notifyBle(self,handle,data):
read_data = class_name.device.char_read(uuid.UUID(read_characteristic))
print(read_data)
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,首先我扫描设备并连接到我的设备并与之绑定,然后我发现特征并列出它们。一切顺利。列出特性后,我写写特性来清除通知标志,它也成功了。最后我订阅通知特性它是成功的。
在所有这些过程之后,我物理地增加了我的设备的计数器(设备上有用于增加计数器的按钮)。当我按下按钮程序转到notifyBle方法时,它给出了错误,即:
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.5/dist-packages/pygatt/backends/gatttool/gatttool.py", line 137, in run
event["callback"](event)
File "/usr/local/lib/python3.5/dist-packages/pygatt/backends/gatttool/gatttool.py", line 479, in _handle_notification_string
self._connected_device.receive_notification(handle, values)
File "/usr/local/lib/python3.5/dist-packages/pygatt/device.py", line 226, in receive_notification
callback(handle, value)
File "/home/acd/Masaüstü/python_workspace/ble.py", line 54, in notifyBle
read_data = bleFunctions.dev.char_read(uuid.UUID(bleFunctions.read_characteristic)) …
Run Code Online (Sandbox Code Playgroud) 我在服务器中监听蓝牙连接:
rfcomm listen rfcomm1 1
Run Code Online (Sandbox Code Playgroud)
然后我连接我的蓝牙客户端并显示以下消息:
Connection from XX:XX:XX:XX:XX:XX to /dev/rfcomm1
Press CTRL-C for hangup
Run Code Online (Sandbox Code Playgroud)
这意味着一切都好......
然后我通过在服务器或客户端中执行Ctrl + C来完成连接.
在此之后,我又做了一次:
rfcomm listen rfcomm1 1
Run Code Online (Sandbox Code Playgroud)
但这一次,当我连接客户端时,我收到此消息:
Can't create RFCOMM TTY: Address already in use
Run Code Online (Sandbox Code Playgroud)
所以我去检查哪些连接是打开的:
rfcomm -a
Run Code Online (Sandbox Code Playgroud)
我可以看到连接显示为关闭,但一旦断开连接就不会出现...
rfcomm1: XX:XX:XX:XX:XX:XX -> XX:XX:XX:XX:XX:XX channel 1 closed [reuse-dlc release-on-hup ]
Run Code Online (Sandbox Code Playgroud)
最奇怪的是,有时断开连接是成功的,我可以毫无问题地重新连接.
编辑
我意识到当设备保持连接大约10秒或更长时间时,断开连接成功.但是当此时间较短(快速连接/断开)时,会出现问题.
如果失败发生,我会:
dmesg
Run Code Online (Sandbox Code Playgroud)
打印出来:
[11800.001527] Bluetooth: TIOCGSERIAL is not supported
[11800.033063] Bluetooth: TIOCGSERIAL is not supported
[11926.708438] Bluetooth: TIOCGSERIAL is not supported
[11934.918197] Bluetooth: TIOCGSERIAL is not supported
[11934.926194] Bluetooth: TIOCGSERIAL …
Run Code Online (Sandbox Code Playgroud) bluez ×10
linux ×6
bluetooth ×4
dbus ×3
raspberry-pi ×3
bash ×1
c ×1
c++ ×1
hci ×1
ibeacon ×1
python ×1
python-2.7 ×1
python-3.x ×1
rfcomm ×1
tty ×1