Bluetooth LE advertising and discovery
A Bluetooth Low Energy device cannot be found unless it says something. Advertising is how it does that. The device sends a short packet, waits, and sends it again, over and over, for as long as it wants to be discoverable. Devices that are listening, or scanning, pick the packets up and decide whether the advertiser is something they care about.
The Bluetooth Core Specification names the two sides of this exchange as roles in its Generic Access Profile. A Broadcaster sends advertising events, and an Observer receives them. A device that advertises and then accepts a connection is acting as a Peripheral, and a device that scans and then opens the connection is acting as a Central. The central and peripheral roles get their own article.
BLE advertising channels
Bluetooth LE divides its band into 40 RF channels, and the Link Layer specification sets aside 3 of them as primary advertising channels, used for initial advertising and all legacy advertising. It uses the other 37 for most other communication.
An advertising event sends the same packet on each primary advertising channel the device uses, then the device waits until the next event. The specification adds a small pseudo-random delay to each interval, so advertising events are spread out in time rather than repeating on an exact schedule. A scanner listens on the advertising channels and collects what it hears. In passive scanning it only receives. In active scanning it can, depending on the advertisement type, ask the advertiser for more information, which comes back as a scan response.
Advertisements come in several types. An advertiser can be connectable or not, and scannable or not. A beacon that only broadcasts a reading is non-connectable. A sensor that wants a phone to connect sends connectable advertisements.
BLE advertising interval
A BLE device advertises as often as it chooses, within limits the Bluetooth Core Specification sets. The advertising interval is a multiple of 0.625 ms and at least 20 ms, and the Link Layer adds a pseudo-random delay of 0 to 10 ms to every advertising event so that two devices on the same interval do not keep colliding. Nordic’s Bluetooth LE course gives the usual range as 20 ms to 10.24 s.
The trade-off is speed of discovery against battery. Nordic puts it simply: the smaller the interval, the more often packets go out and the more power the device uses. Android’s AdvertisingSetParameters builds that trade-off into three presets:
- About every 100 ms, for low latency. Android says this has the highest power consumption and should not be used for continuous background advertising. It is also the shortest interval Android lets an app set.
- About every 250 ms, balanced between advertising frequency and power.
- About every 1,000 ms, the default and preferred mode, because it uses the least power.
A product can also change its interval over time. Google’s Matter documentation says a device waiting to be set up advertises every 20 to 60 ms for the first 30 seconds after it is turned on, then every 150 to 1,500 ms, and stops its Bluetooth LE advertisement once it joins its first fabric. How much battery does BLE use? covers the rest of the power budget.
BLE advertisement payload structure
A BLE advertisement payload is a sequence of AD structures. The Generic Access Profile defines the format: each structure starts with a one-octet length, then an AD type, then the data. The AD type values, such as Flags, lists of service UUIDs, the local name and manufacturer-specific data, are registered in the Bluetooth SIG’s Assigned Numbers.
The most useful item for app developers is usually a service UUID. A scanner can filter on it and ignore everything else, which is how an app finds its own devices in a room full of headphones and watches. The UUID identifies a GATT service that the device offers once connected; GATT services and characteristics explains that structure.
BLE advertisement data size
Legacy advertising packets are small: Android’s BluetoothLeAdvertiser reference says an advertiser can broadcast up to 31 bytes of advertisement data, and that if the advertisement is connectable, three bytes are added for flags.
Extended advertising, an option in the Link Layer specification, moves most of the data off the three primary channels onto secondary channels and lets the controller split it across a chain of packets. The specification caps host advertising data at 1650 octets before fragmentation. Not every phone supports it: Android exposes isLeExtendedAdvertisingSupported and getLeMaximumAdvertisingDataLength on BluetoothAdapter so apps can check.
| Legacy advertising | Extended advertising | |
|---|---|---|
| Advertising data | Up to 31 bytes, per Android’s BluetoothLeAdvertiser | Up to 1,650 octets of host data, fragmented across packets whose payload is at most 255 octets |
| Channels | The 3 primary advertising channels | Starts on the primary channels and carries the data on the secondary channels, the 37 general-purpose channels |
| Bluetooth version | The Bluetooth 4.x format, which Android calls 4.x spec compliant advertising | Bluetooth 5 advertising extensions |
| On Android | Every device that supports LE advertising | Android 8.0 and later with a compatible controller; check isLeExtendedAdvertisingSupported |
iOS and Android BLE advertising limits
Mobile operating systems add their own limits on top of the specification.
iOS. Apple’s startAdvertising(_:) documentation says the peripheral manager supports only two advertising keys, the local name and service UUIDs. In the foreground an app can use up to 28 bytes of the initial advertisement for those keys, plus 10 bytes of scan response space for the local name only, not counting the 2 bytes of header each data type needs. Service UUIDs that do not fit go to an overflow area that only iOS devices explicitly scanning for them can discover. In the background, the local name is not advertised and every service UUID goes to the overflow area. Apple also describes advertising as best effort, because several apps may be advertising at once.
Android. Apps advertise with BluetoothLeAdvertiser, which can return null when the device does not support LE advertising. Scanning has its own rules: the BluetoothLeScanner reference says unfiltered scans stop when the screen turns off, so apps that need to keep finding devices pass a scan filter.
These rules shape app design. Two phones that rely on a custom service UUID to find each other in the background can fail to meet, even though each one works in the foreground.
BLE advertising for smart home setup
BLE advertising is how a new device tells a nearby phone that it is waiting to be set up. In Matter, Google’s documentation says an uncommissioned device acts as a GAP peripheral and advertises its uncommissioned state over Bluetooth LE. The phone doing the setup scans passively on the three advertising channels, matches the device against the discriminator from its setup code, and connects. Apple’s Matter documentation says that once the user scans the setup code, the iPhone provisions the accessory onto Wi-Fi or Thread. What is Matter? explains the rest of the standard.
Wi-Fi provisioning starts the same way. Espressif’s unified provisioning for the ESP32 can run over Bluetooth LE: the device advertises its name or primary service, a phone app finds it and connects, and the Wi-Fi credentials travel over GATT characteristics. Espressif publishes provisioning apps for Android and iOS. How can an ESP32 send data to a phone without Wi-Fi? covers the other things a phone and a microcontroller can do over the same link.
BLE advertising privacy
BLE advertising data is public: it is broadcast in the clear to anyone in range. Do not put secrets, personal names or stable identifiers in it that would let someone track a device over time. Keep it to what a scanner needs to decide whether to connect, and move everything else to an encrypted exchange after the connection is made.