有没有增加BLE的BlueZ广告频率的方法吗? [英] Is there a way to increase BLE advertisement frequency in BlueZ?

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

问题描述

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

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集广告参数。前两个字节A0 00是最小间隔,第二个两字节A0 00是最大间隔。在这个例子中,它设置100ms的通告之间的时间。该设置的粒度为0.625ms,所以间隔设置为01套00的广告去的每0.625ms,把它设为A0 00集的广告去每0XA0 * 0.625ms = 100毫秒。将其设置为40 06集的广告去每0x0640 * 0.625ms = 1000毫秒。第五字节,03,设置广告模式向非连接。对于非连接广告,可以做广告最快为100ms,具有广告连接(0×00),你可以做广告快得多。

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设置广告启用。有必要发出带有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问题上的一个较慢的集广告interval命令的通知。

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆