How to Increase Ble Advertisement Frequency in Bluez

Is there a way to increase BLE advertisement frequency in BlueZ?

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.

Is there a way to advertise multiple beacons with BlueZ

Yes, your device can act as several BLE beacons as long as you periodically change the advertising payload. Your suggestion of using LE Set Advertising Data Command is my recommended approach and you don't need to change the advertising channel for this purpose.

In other words, what you can do on your device is set up a timer, and then as soon as the timer expires, you can switch to a different set of BLE data that is being advertised, which will create the affect of your device acting as multiple beacons.

Please see the following links which may be helpful to your question as well:-

  • Can BLE devices act as beacons
  • advertise custom service uuid with bluez 5.4x
  • Linux BlueZ custom Manufacturing Scan Response Data
  • Bluez BLE peripheral advertise custom characteristic with ADV data

I hope this helps.

How to check if BLE advertisement is already enabled (HCI)

The idea is that the Bluetooth stack on the host side should know if it has started advertising or not. That's how it should work. If you manually bypass the Bluetooth stack on the host side (which you shouldn't do unless you are debugging or something), sending your own hci command, then you can't know.

BLE Advertisement switch interval & advertising interval

The fastest I have been able to reliably switch between two BLE advertisements on iOS is 1 second. See my answer and sample code here.

The standard iOS iBeacon advertising frequency is 30 Hz, but in my experience, you only need to transmit an iBeacon advertisement every 900ms for fastest detection. More frequent advertisements are still useful for more accurate distance measurements, as iOS uses samples of RSSI from the iBeacon advertisements to make this estimate every second when ranging.

BLE advertising channel

You can set the chan_map using the le_set_advertising_parameters structure to advertise on the particular channel



Related Topics



Leave a reply



Submit