【发布时间】:2021-10-23 20:34:38
【问题描述】:
我目前正在使用 BlueZ DBus API 扫描 BLE 设备,但它在不同的时间间隔后完全停止响应。有时是几分钟,有时是一两个小时。
我的假设是我忘了做某事。奇怪的是,在我退出应用程序后,bluetoothctl 和hciconfig 之类的工具也不再响应。有时重新启动不足以让它再次工作,我需要重新启动机器。它也发生在几台不同的机器上。
我正在使用以下方式获取公共汽车:
GError* error = nullptr;
mConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
开始循环:
mLoop = g_main_loop_new(nullptr, false);
g_main_loop_run(mLoop);
然后我通过将Powered 属性设置为true 并调用StartDiscovery 来启动适配器。然后通过以下方式报告设备:
guint iface_add_sub = g_dbus_connection_signal_subscribe(mConnection, "org.bluez", "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", nullptr, nullptr, G_DBUS_SIGNAL_FLAGS_NONE, device_appeared, this, nullptr);
guint iface_remove_sub
= g_dbus_connection_signal_subscribe(mConnection, "org.bluez", "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved", nullptr, nullptr, G_DBUS_SIGNAL_FLAGS_NONE, device_disappeared, this, nullptr);
为了阻止 BlueZ 停止响应,我是否遗漏了什么?
- 蓝牙-v = 5.53
- ldd --version = GLIBC 2.31-0ubuntu9.2
【问题讨论】:
-
我会尝试在 bluetoothd 卡住时将调试器附加到它。不保证会产生有用的信息,但它可能会! (这就是为什么开源很棒)
-
看来至少日志中没有很多信息(在添加-d之后)。它只是停止记录,没有任何明显的错误。
-
调试器意味着gdb