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
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.
Bluetooth advertising is permission based advertising, which means that when a mobile device has received a Bluetooth message, the recipient has the choice to either accept or decline the message. The recipient needs to positively indicate that they wish to receive marketing messages.
The device advertises on three channels. The advertising channels are channel 37 (2402 MHz), channel 38 (2426 MHz), and channel 39 (2480 MHz).
The recommended advertising pattern and advertising intervals are: First, advertise at 20 ms intervals for at least 30 seconds. If not discovered after 30 seconds, you may change to one of the following longer intervals: 152.5 ms, 211.25 ms, 318.75 ms, 417.5 ms, 546.25 ms, 760 ms, 852.5 ms, 1022.5 ms, 1285 ms.
Hi, While using the BLE advertising module, it struck me that it automatically stops advertising as soon as a device connects. This is not acceptable in my application as several clients has to be able to be connected to the device simultaneously.
I think I figured it out.
Instead of:
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
Do this:
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
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.
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.
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.
Note that all of this is based on the IOGear GBU521, so this may not work with other Bluetooth LE chipsets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With