- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写一个简单的代理应用程序。
我能够配对我的设备,但是当我尝试连接时(点击连接选项)它失败并显示以下 dbus 日志
非常感谢您的帮助。
method call time=1537417845.746765 sender=:1.0 -> destination=:1.25 serial=2824 path=/org/bluez/AutoPinAgent; interface=org.bluez.Agent1; member=AuthorizeService
object path "/org/bluez/hci0/dev_00_00_00_17_55_B8"
string "00001108-0000-1000-8000-00805f9b34fb"
error time=1537417845.749340 sender=:1.25 -> destination=:1.0 error_name=org.freedesktop.DBus.Error.UnknownMethod reply_serial=2824
string "No such interface 'org.bluez.Agent1' on object at path /org/bluez/AutoPinAgent"
最佳答案
如果没有代理的源代码以及您尝试连接的方式,真的很难判断。从日志中可以清楚地看到,当守护进程尝试连接 HSP 配置文件的 HS(耳机)角色 时,它正在通过调用代理的 AuthorizeService
请求授权。 p>
从错误回复中,我了解到您没有在 Bluez 中正确注册方法/接口(interface)。因此,您需要实现 AuthorizeService
并在尝试为此配置文件连接时授权该服务。
以下是实现 Bluez 的 doc/agent-api.txt 的 Agent 示例。所以你需要根据自己的需要在本例中实现AuthorizeService
。本示例只是模板代码,没有具体实现。
/*
* gcc `pkg-config --cflags glib-2.0 gio-2.0` -Wall -Wextra -o ./bin/agent ./agent.c `pkg-config --libs glib-2.0 gio-2.0`
*/
#include <glib.h>
#include <gio/gio.h>
#include <stdio.h>
GMainLoop *loop;
GDBusConnection *con;
#define AGENT_PATH "/org/bluez/AutoPinAgent"
static void bluez_agent_method_call(GDBusConnection *conn,
const gchar *sender,
const gchar *path,
const gchar *interface,
const gchar *method,
GVariant *params,
GDBusMethodInvocation *invocation,
void *userdata)
{
int pass;
int entered;
char *opath;
GVariant *p= g_dbus_method_invocation_get_parameters(invocation);
g_print("Agent method call: %s.%s()\n", interface, method);
if(!strcmp(method, "RequestPinCode")) {
;
}
else if(!strcmp(method, "DisplayPinCode")) {
;
}
else if(!strcmp(method, "RequestPasskey")) {
g_print("Getting the Pin from user: ");
fscanf(stdin, "%d", &pass);
g_print("\n");
g_dbus_method_invocation_return_value(invocation, g_variant_new("(u)", pass));
}
else if(!strcmp(method, "DisplayPasskey")) {
g_variant_get(params, "(ouq)", &opath, &pass, &entered);
g_dbus_method_invocation_return_value(invocation, NULL);
}
else if(!strcmp(method, "RequestConfirmation")) {
g_variant_get(params, "(ou)", &opath, &pass);
g_dbus_method_invocation_return_value(invocation, NULL);
}
else if(!strcmp(method, "RequestAuthorization")) {
;
}
else if(!strcmp(method, "AuthorizeService")) {
;
}
else if(!strcmp(method, "Cancel")) {
;
}
else
g_print("We should not come here, unknown method\n");
}
static const GDBusInterfaceVTable agent_method_table = {
.method_call = bluez_agent_method_call,
};
int bluez_register_agent(GDBusConnection *con)
{
GError *error = NULL;
guint id = 0;
GDBusNodeInfo *info = NULL;
static const gchar bluez_agent_introspection_xml[] =
"<node name='/org/bluez/SampleAgent'>"
" <interface name='org.bluez.Agent1'>"
" <method name='Release'>"
" </method>"
" <method name='RequestPinCode'>"
" <arg type='o' name='device' direction='in' />"
" <arg type='s' name='pincode' direction='out' />"
" </method>"
" <method name='DisplayPinCode'>"
" <arg type='o' name='device' direction='in' />"
" <arg type='s' name='pincode' direction='in' />"
" </method>"
" <method name='RequestPasskey'>"
" <arg type='o' name='device' direction='in' />"
" <arg type='u' name='passkey' direction='out' />"
" </method>"
" <method name='DisplayPasskey'>"
" <arg type='o' name='device' direction='in' />"
" <arg type='u' name='passkey' direction='in' />"
" <arg type='q' name='entered' direction='in' />"
" </method>"
" <method name='RequestConfirmation'>"
" <arg type='o' name='device' direction='in' />"
" <arg type='u' name='passkey' direction='in' />"
" </method>"
" <method name='RequestAuthorization'>"
" <arg type='o' name='device' direction='in' />"
" </method>"
" <method name='AuthorizeService'>"
" <arg type='o' name='device' direction='in' />"
" <arg type='s' name='uuid' direction='in' />"
" </method>"
" <method name='Cancel'>"
" </method>"
" </interface>"
"</node>";
info = g_dbus_node_info_new_for_xml(bluez_agent_introspection_xml, &error);
if(error) {
g_printerr("Unable to create node: %s\n", error->message);
g_clear_error(&error);
return 0;
}
id = g_dbus_connection_register_object(con,
AGENT_PATH,
info->interfaces[0],
&agent_method_table,
NULL, NULL, &error);
g_dbus_node_info_unref(info);
//g_dbus_connection_unregister_object(con, id);
/* call register method in AgentManager1 interface */
return id;
}
static int bluez_agent_call_method(const gchar *method, GVariant *param)
{
GVariant *result;
GError *error = NULL;
result = g_dbus_connection_call_sync(con,
"org.bluez",
"/org/bluez",
"org.bluez.AgentManager1",
method,
param,
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if(error != NULL) {
g_print("Register %s: %s\n", AGENT_PATH, error->message);
return 1;
}
g_variant_unref(result);
return 0;
}
static int bluez_register_autopair_agent(const char *cap)
{
int rc;
rc = bluez_agent_call_method("RegisterAgent", g_variant_new("(os)", AGENT_PATH, cap));
if(rc)
return 1;
rc = bluez_agent_call_method("RequestDefaultAgent", g_variant_new("(o)", AGENT_PATH));
if(rc) {
bluez_agent_call_method("UnregisterAgent", g_variant_new("(o)", AGENT_PATH));
return 1;
}
return 0;
}
static void cleanup_handler(int signo)
{
if (signo == SIGINT) {
g_print("received SIGINT\n");
g_main_loop_quit(loop);
}
}
int main(int argc, char **argv)
{
int id;
int rc;
if(argc < 2)
return 1;
if(signal(SIGINT, cleanup_handler) == SIG_ERR)
g_print("can't catch SIGINT\n");
con = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
if(con == NULL) {
g_print("Not able to get connection to system bus\n");
return 1;
}
loop = g_main_loop_new(NULL, FALSE);
id = bluez_register_agent(con);
if(id == 0)
goto fail;
rc = bluez_register_autopair_agent(argv[1]);
if(rc) {
g_print("Not able to register default autopair agent\n");
goto fail;
}
g_main_loop_run(loop);
fail:
g_dbus_connection_unregister_object(con, id);
g_object_unref(con);
return 0;
}
在编写我们自己的源代码之前,始终最好从基于 bluetoothctl
CLI 的配对和连接开始。
关于c - 在 dbus 上用 C 语言进行 Bluez 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52418268/
我正在尝试使用 BlueZ 4.X DBus 接口(interface)在 Linux 上建立与蓝牙 4.0 LE 设备的连接。 为了测试这一点,我使用以下命令: dbus-send --system
我有一个连接到 Linux 设备的蓝牙耳机。我想以编程方式接收播放/暂停/下一个/上一个/volUp/volDown 按钮按下。 经过一些研究,我发现我可以使用 dbus 与 Bluez 交互。我尝试
我正在使用 BlueZ 3.x.我有一个 linux 嵌入式设备,我需要使用蓝牙技术发送和接收文件,使用 Obex . (注意:BlueZ 4.x 甚至无法在我们的特定平台上编译。) 我不需要 PIN
Linux下的bluez是否可以同时连接多个经典和低能耗设备? bluez 网站提供这样的信息不是很有帮助。 最佳答案 是的,我已成功同时连接到 7 个低能耗设备。最大值因您使用的硬件而异。您还可以连
我有一个自定义 GATT 服务器,作为插件在 Linux 上使用 BlueZ 4.101。我现在正在尝试设置自定义扫描响应广告数据。我在 iOS 上使用 LightBlue 来调试我的 GATT 服务
我想在测试设置中实现的是: 运行: hcitool -i hci0 lescan --duplicates --passive 在一个外壳上 并联在另一个via上 hcitool -i hci0 le
我正在使用 Fedora 24。对于我的论文,我必须从源代码构建 BlueZ,因为我需要实验性功能。现在,最佳做法是什么?在从源代码重新安装之前,我是否必须从操作系统中删除 BlueZ?当我尝试使用
传输端点未连接 #include #include #include #include #include int main(int argc, char **argv) { struct s
用例 Ubuntu 机器正在模拟键盘 Ubuntu 机器(虚拟键盘)模拟连接到要控制的远程设备 问题 在正常情况下,HID 描述是通过 SDP 报告的,因此,当设备连接到键盘时,它已经知道要使用的 H
我正在用 C 为 Bluez 5.18 编写插件代码,我想创建自己的 BLE GATT 配置文件作为插件(共享库)。我需要从主代码调用函数,当我编译它时,没有错误,但是在加载插件时,它因 undefi
我正在使用 Raspberry Pi(运行 Jessie)、Bluez 和 iBeacons(10 个 iBeacons)。我的应用程序(用 Python 编写)嗅探 iBeacons 并报告 MAC
在一天的大部分时间里,我一直在努力让 BlueZ 在我的 Ubuntu 桌面上运行。它只是行不通。我可以通过系统对话成功地将我的设备与我的计算机配对,但 BlueZ 扫描从未发现任何东西。有没有 Bl
我正在浏览 Device API在 BlueZ 5.44 中,我对连接和配对设备之间的区别有点困惑。我看到连接是基于配置文件的,而配对似乎独立于配置文件。配对似乎更多地与 SDP 和身份验证有关。 但
如何重建 bluez?是否可以?例如,我想更改 avctp.c 中的某些内容。我从他们的网站下载了最新的 bluez 版本并进行了我需要的更改。现在,我如何使更改生效;即我需要做什么来重建 bluet
我在 linux 中使用内核版本 3.0.35 和 bluez-4.98。有了这个,我就可以根据其中一个 SO 问题中给出的 hcitool 命令来宣传 ibeacon。我也能够连接到其他 ble 设
我正在用 C/C++ 为低功耗蓝牙设备编写一个库。到目前为止,我一直在使用 Bluez 公开的 D-Bus 接口(interface),并且能够发现、连接设备并与之通信。 但是,当设备由于链接故障或超
我编写了一个 Python 程序,它通过蓝牙套接字(参见下面的示例)读取和写入 L2CAP 连接以与某些硬件通信。然而,代码可能想要为蓝牙适配器做太多的 IO 处理,所以我通过在需要时放慢 bar 循
说明: 我有一个带有蓝牙功能的小型内部设备。 目前,其他设备连接到该盒子。 需求: 现在我们必须使它成为奴隶,以便它与其他设备连接。我想知道该怎么做?我不需要源代码或任何只是你的意见。 附加信息: 该
我在我的 Linux 板上使用 bluez 附带的 example-gatt-server.py 脚本。我想向我的自定义特征之一添加通知。为此,我需要定义客户端特征配置描述符并将其添加到我的自定义特征
使用 BlueZ 蓝牙堆栈,如何以编程方式枚举已配对但不一定连接的设备? 最佳答案 更新:下面的内容并不像我最初想象的那么简单。 adapter_get_devices 只是起点。如果您可以发布其中的
我是一名优秀的程序员,十分优秀!