本文介绍了有没有办法增加 BlueZ 中的 BLE 广告频率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台使用以下命令广播 BLE 广告的 linux 计算机:

I have a linux computer broadcasting a BLE advertisement using the following commands:

 sudo hciconfig hci0 up
 sudo hcitool -i hci0 cmd 0x08 0x0008 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 c5 00 00 00 00 00 00 00 00 00 00 00 00 00
 sudo hciconfig hci0 leadv 3

这很有效,但计算机每秒只播放一次蓝牙广告.我想将此频率增加到每秒 10 次或更多.有没有办法提高 BlueZ 的广告频率?还是每秒一次是标准且不可更改的?如果无法使用命令行工具,我很乐意使用 C API 来做到这一点.

This works well but the computer only broadcasts its bluetooth advertisement once a second. I would like to increase this frequency to 10 times per second or more. Is there a way to increase advertising frequency in BlueZ? Or is once per second the standard and unchangeable? I'm happy to do this with C APIs if not possible with command line tools.

推荐答案

我想我明白了.

代替:

sudo hciconfig hci0 up
sudo hcitool -i hci0 cmd 0x08 0x0008 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 c5 00 00 00 00 00 00 00 00 00 00 00 00 00
sudo hciconfig hci0 leadv 3

这样做:

sudo hciconfig hci0 up
sudo hcitool -i hci0 cmd 0x08 0x0008 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 c5 00 00 00 00 00 00 00 00 00 00 00 00 00
sudo hcitool -i hci0 cmd 0x08 0x0006 A0 00 A0 00 03 00 00 00 00 00 00 00 00 07 00
sudo hcitool -i hci0 cmd 0x08 0x000a 01

第二个 hcitool 命令 (0x08 0x0006) 是LE Set Advertising Parameters.前两个字节 A0 00 是最小间隔".后两个字节 A0 00 是最大间隔".在这个例子中,它设置广告之间的时间间隔为100ms.这个设置的粒度是0.625ms,所以设置interval为01 00,设置为每0.625ms播放一次.设置为A0 00设置为每0xA0*0.625ms = 100ms播放一次.将其设置为 40 06 设置广告每 0x0640*0.625ms = 1000ms 播放一次.第五个字节 03 设置广告模式为不可连接.对于不可连接的广告,您可以做的最快广告为 100 毫秒,使用可连接的广告 (0x00),您可以更快地做广告.

The second hcitool command (0x08 0x0006) is "LE Set Advertising Parameters. The first two bytes A0 00 are the "min interval". The second two bytes A0 00 are the "max interval". In this example, it sets the time between advertisements to 100ms. The granularity of this setting is 0.625ms, so setting the interval to 01 00 sets the advertisement to go every 0.625ms. Setting it to A0 00 sets the advertisement to go every 0xA0*0.625ms = 100ms. Setting it to 40 06 sets the advertisement to go every 0x0640*0.625ms = 1000ms. The fifth byte, 03, sets the advertising mode to non-connectable. With a non-connectable advertisement, the fastest you can advertise is 100ms, with a connectable advertisment (0x00) you can advertise much faster.

第三个 hcitool 命令 (0x08 0x000a) 是LE Set Advertise Enable".必须使用 hcitool 而不是 hciconfig 发出此命令,因为hciconfig hci0 Leadv 3"会自动将广告速率设置为较慢的默认值 1280ms.

The third hcitool command (0x08 0x000a) is "LE Set Advertise Enable". It is necessary to issue this command with hcitool instead of hciconfig, because "hciconfig hci0 leadv 3" will automatically set the advertising rate to the slower default of 1280ms.

我通过在运行您在问题中发布的原始命令的同时运行 hcidump 来解决这个问题.这向您展示了一组由 bluez 执行的原始 hcitool 命令(很好地注释了它们的作用).我刚好从 hcidump 输出中注意到hciconfig hci0 Leadv 3"发出了一个较慢的设置广告间隔命令.

I figured this out by running hcidump at the same time as running the original commands you posted in the question. This shows you a bunch of raw hcitool commands (nicely annotated for what they do) that get executed by bluez. I just happened to notice from the hcidump output that "hciconfig hci0 leadv 3" issues its a slower set advertising interval command.

请注意,所有这些都基于 IOGear GBU521,因此这可能不适用于其他蓝牙 LE 芯片组.

Note that all of this is based on the IOGear GBU521, so this may not work with other Bluetooth LE chipsets.

这篇关于有没有办法增加 BlueZ 中的 BLE 广告频率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 12:48