python-3.xbluetooth-lowenergyibeaconbluez

Does selecting a specific advertising channel in iBeacon BLE lead to lower transmission speed?


Im actually trying to select a specific channel using the command parameter Advertising_Channel_Map, the values it has are 0x01 (channel 37), 0x02 (channel 38), 0x04 (channel 39) and 0x07 (default, all channels enable).

The line of my code (in python) that modifies it is:

cmd_pkt = struct.pack("<HHBBBBBBBBBBB", 0x00A0, 0x00A0, ADV_NONCONN_IND, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, advertising_channel_map, 0x00)

As you can see, the variable advertising_channel_map in my python code, depending on the channel I want to send packages, it takes the values 0x01, 0x02 and 0x04.

The previous code line is the same as use this HCI command:

sudo hcitool -i hci0 cmd 0x08 0x0006 A0 00 A0 00 03 00 00 00 00 00 00 00 00 07 00

Where the 07 represents the default advertising channel map in this case as I previously said, but it can takes the values 0x01, 0x02 and 0x04 too.

I used mobile applications to send advertising packets to a sniffer I have, and the transmission speed was excellent. However, when I implemented my own code and selected channels 37, 38, and 39, the speed significantly dropped. Only when I set the value of 0x07 for the advertising_channel_map did it perform similarly to the mobile apps.

When I send on a specific channel it takes around 30-32 seconds to send 100 packages meanwhile on default mode (0x07) it takes only 10-12 seconds.

Also, I configured the major and minor values with the channel number I am using, so that I can recognize which channel is being used at any given moment when I unpack the packet. I don't know if this can lead to errors.

Is there any way to increase the transmission speed on a specific channel (37, 38 and 39) or am I missing something in the code?


Solution

  • If an advertiser sends the packet on multiple channels, it usually sends it on all channels in sequence, with a very short channel switching period. When finished, it sleeps for about one advertising interval and then restarts.

    A BLE device usually only has one antenna and one radio, meaning it can only do one operation at a time, including being tuned to a specific channel at a time. So, a scanner usually cycles around among the three advertising channels. The time spent each time for a channel is usually the scan interval that is set over hci. This means that if an advertiser only transmits a packet on one channel, it's only 1/3 chance that a packet will be detected by the scanner. It seems this matches with your results. The only way to improve the scanner would be to upgrade its hardware to have three radios (so it can scan three channels in parallel), but this is not how most (any?) Bluetooth chip works.

    The rationale for sending on three channels is to avoid the risk of interference on a specific channel hiding all advertisements. If you want to save power by only sending on one channel, consider instead to send on all three channels but have a 3x longer advertisement interval.