Bluetooth Low Energy

What is BLE advertising?

BLE advertising is how a Bluetooth Low Energy device announces that it exists. The device repeatedly broadcasts small packets on dedicated advertising channels, carrying data such as a name or service identifiers, and any nearby device that is scanning can receive them, read the data and, if the advertiser allows it, ask to connect.

TL;DR

A BLE device can only be found if it advertises, and the most useful thing in its small payload is usually a service UUID that scanners filter on. Legacy advertisements carry up to 31 bytes, and iOS and Android limit what apps can advertise and scan in the background. Advertisements are public, so keep them to what a scanner needs.

Learning objectives

After reading this article you will be able to:

  • Describe how advertising events use the primary advertising channels
  • Explain how an advertisement is built from AD structures and how much fits
  • Identify the limits iOS and Android place on what apps can advertise

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 advertisingExtended advertising
Advertising dataUp to 31 bytes, per Android’s BluetoothLeAdvertiserUp to 1,650 octets of host data, fragmented across packets whose payload is at most 255 octets
ChannelsThe 3 primary advertising channelsStarts on the primary channels and carries the data on the secondary channels, the 37 general-purpose channels
Bluetooth versionThe Bluetooth 4.x format, which Android calls 4.x spec compliant advertisingBluetooth 5 advertising extensions
On AndroidEvery device that supports LE advertisingAndroid 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.

Frequently asked questions

Does a device need to be connected to read advertising data?

No. Advertising data is broadcast, so any device that is scanning in range can receive it without connecting or pairing. That is also why it should never carry anything secret.

Why does my iPhone app's advertisement disappear in the background?

Apple's documentation says that while an app is in the background, the local name is not advertised and all service UUIDs move to an overflow area that only an iOS device explicitly scanning for them can discover. An Android phone scanning for the service UUID will not see it there.

How many advertising channels does Bluetooth LE use?

Three. The Link Layer specification sets aside 3 of the 40 RF channels as primary advertising channels, used for initial advertising and all legacy advertising.

What is extended advertising in Bluetooth LE?

An option in the Link Layer specification that moves most of the advertising 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.

What can an iOS app put in a BLE advertisement?

Only the local name and service UUIDs. In the foreground it 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.

What is the difference between passive and active BLE scanning?

In passive scanning, the scanner only receives advertisements. In active scanning it can, depending on the advertisement type, ask the advertiser for more information, which comes back as a scan response.

Sources

Build it with Offline Protocol

In the Offline Protocol mesh SDK, starting the protocol with BLE enabled both scans for nearby devices advertising the Offline Protocol service and advertises the local device. The lifecycle reference lists what start and stop do and the permissions each platform needs.

Read the lifecycle reference