gpt4 book ai didi

javascript - BLE 主机 : scanning while connected

转载 作者:行者123 更新时间:2023-11-30 16:13:26 25 4
gpt4 key购买 nike

基本上我的问题与BLE peripheral: scanning while connected非常相似,只是我指的是主机而不是外围设备。

如果主机已经连接到一个或多个外围设备,它是否仍然能够扫描其他进行广告的外围设备?

我也在使用 bleno 作为外设,使用 noble 作为主控,但我认为这个问题的答案不依赖于实际的模块,而是蓝牙低功耗规范,是吗?

最佳答案

是的,中央可以在与其他外围设备建立连接时进行扫描。请注意,单个外围设备在连接到中央设备时可能会停止广播。这可能会在测试时增加困惑。

这是一个使用 noble 的最小演示:

var noble = require('noble');
var connectedIDs = {};

noble.on('stateChange', (state) => {
if (state == 'poweredOn') {
noble.startScanning([], true);
}
});

noble.on('discover', (peripheral) => {
if (connectedIDs[peripheral.id] == 'known') {
console.log(new Date() + ' ' + peripheral.id + ' discovered again');
} else {
console.log(new Date() + ' ' + peripheral.id + ' discovered first time')
connectedIDs[peripheral.id] = 'known';
// periodically connect to the same peripheral so we get the error
// message telling us that we are already connected
setInterval( () => {
peripheral.connect( (err) => {
if (err) {
console.log(new Date() + ' ' + peripheral.id + ' ' + err);
return;
}
console.log(new Date() + ' ' + peripheral.id + ' connected');
});
}, 1000);
}
});

此代码示例连接到它发现的所有外围设备,并同时记录它从中接收广告数据的外围设备的 ID。

输出( chop 了一些列和行):

10:51:06 8652... Error: Peripheral already connected
10:51:06 567b... Error: Peripheral already connected
10:51:06 f0ba... Error: Peripheral already connected
10:51:06 d095... Error: Peripheral already connected
10:51:06 3800... Error: Peripheral already connected
10:51:07 6c20... discovered first time
10:51:07 f0ba... Error: Peripheral already connected
10:51:07 d095... Error: Peripheral already connected
10:51:07 3800... Error: Peripheral already connected
10:51:07 6c20... discovered again
10:51:08 8652... Error: Peripheral already connected
10:51:08 567b... Error: Peripheral already connected
10:51:08 f0ba... Error: Peripheral already connected
10:51:08 6c20... discovered again
10:51:08 d095... Error: Peripheral already connected
10:51:08 8652... Error: Peripheral already connected
10:51:08 3800... Error: Peripheral already connected
10:51:08 6c20... discovered again
10:51:08 f0ba... Error: Peripheral already connected
10:51:08 d095... Error: Peripheral already connected
10:51:08 3800... Error: Peripheral already connected
10:51:08 6c20... connected
10:51:08 6c20... connected

发生了什么?

6c20...第一次被发现时,已经有多个外设连接到noble。重复连接尝试的错误消息显示外围设备在扫描时仍处于连接状态。在我的示例运行中,我连接了 6 个 BLE 外设,6c20... 是第 7 个加入的。我在 2015 年中期使用 OS X 10.11.3 的 MacBookPro 上使用了 noble v1.3.0 和 node v4.2.4。

这没有回答第二个问题:此行为是否取决于实际模块或蓝牙低功耗规范?

据我所知,BLE 规范没有指定中央必须支持的连接数量。 AFAIK 因为 BLE 核心规范相当大,所有对同时和多个连接的引用我都可以找到它取决于实现的状态。所以,这似乎完全取决于由硬件和软件组成的BLE产品。即使 BLE 规范会指定它,我也更愿意查看产品的数据表。此外,它也取决于主机上运行的软件。幸运的是,noble 做到了。

举个例子,我们看一下Nordic的Soft Device S120的datasheet:https://www.nordicsemi.com/eng/nordic/download_resource/26275/14/32008006

S120 软设备是 Nordic NRF51 系列 BLE IC(最著名的例子是 nRF51822)的 BLE 堆栈(固件)。

这里引用上面链接的数据表:

The SoftDevice supports eight concurrent master connections and an additional Scanner/Initiator role. When the maximum number of simultaneous connections are established, the Scanner role will be supported for new device discovery though the initiator is not available at that time.

关于javascript - BLE 主机 : scanning while connected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35886204/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com