bluetooth - bluez 同时具有经典和低能耗设备

标签 bluetooth bluetooth-lowenergy bluez

Linux下的bluez是否可以同时连接多个经典和低能耗设备? bluez 网站提供这样的信息不是很有帮助。

最佳答案

是的,我已成功同时连接到 7 个低能耗设备。最大值因您使用的硬件而异。您还可以连接到多个经典设备。

这是我用于通过 L2CAP 连接的一些伪/片段:

#include <sys/types.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>

char *bdaddr;
int cid = 0;
int psm = 0;
int bdaddr_type = BDADDR_LE_PUBLIC;
int err;
struct sockaddr_l2 addr;
int sock_fd = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)

memset(&addr, 0, sizeof(addr));
addr.l2_family = sock->sock_family;
str2ba(bdaddr, &addr.l2_bdaddr);

if (cid)
    addr.l2_cid = htobs(cid);
else
    addr.l2_psm = htobs(psm);

addr.l2_bdaddr_type = bdaddr_type;


err = connect(sock_fd, (struct sockaddr *) &addr, sizeof(addr));

我的代码是 C 和 Python 的混合,所以我尝试重构它,使其只剩下 C 部分。所有内容均来自阅读 Bluez 源代码,特别是 gatttool

更新: 3.4 及之前版本的 Linux 内核的 bluez 代码在处理 L2CAP 套接字时存在一个错误。本质上,如果您有多个连接,它会将它们混合在一起,以便您获得最后一个连接上的所有数据。因此,如果您只建立一个 L2CAP 连接,我给出的代码仅适用于内核 3.4 及更早版本。

关于bluetooth - bluez 同时具有经典和低能耗设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18364279/

相关文章:

bluetooth - 使用 bluez/bluetoothctl/gatttool 连接到蓝牙智能/LE 体重秤

java - 发送车辆特定的 OBDII 命令

linux - 无法在树莓派上使用 bluez-tools 将蓝牙设备设置为受信任

bluetooth-lowenergy - BLE 规范是否允许在广告数据和扫描响应中使用制造商广告类型?

security - 低功耗蓝牙 GATT 安全级别

android - 使用 Android 应用程序找不到蓝牙服务

ios - 在哪里可以找到 BR-LE4.0-S2A 技术规范。即服务和特征的 UUID 列表?

linux - 更改 Tx Bluetooth Linux 无效

c - 无法使用 C 中 API 库 header 中定义的结构

node.js - BLE外设: scanning while connected