Advertising

Advertising is a process used for BLE modules to send data to other BLE devices. This data is packed in advertisements, which are modifiable by the user, so they represent an easy way of sending data without the need of connecting first.

The advertisements contain information about address of the advertiser, discoverability and connectability modes, TX power level, application data, etc. They can be built according to the Bluetooth standard or customized by the user to send its own data, as It is described later.

Configuring advertisements

There are some parameters which allow the advertisement configuration. For example, the user will be able to configure which nodes can see the Waspmote BLE module advertisements. Below all possibilities are described.

Visibility - GAP discoverable modes

The way of controlling who is able to see the advertisements of a BLE node is modifying the GAP discoverable mode with the function setDiscoverableMode(). The possibilities are shown below:

  • Non discoverable: Device is not advertising

  • Limited discoverable: Device will be visible using limited discoverable scanning mode

  • General discoverable: Device will be visible using general discoverable scanning mode

  • Broadcast: Same as non discoverable

  • User Data: Send advertisement data defined by user

  • Enhanced broadcasting: Scanning devices are reported back to the application

Example:

{
    // start advertising in general discoverable mode
    BLE.setDiscoverableMode(BLE_GAP_GENERAL_DISCOVERABLE);
}

Conectability -- GAP connectable modes

The user can also specify who can connect to the node, setting a flag inside the advertisement with the choices listed below. It can be done also with function setConnectableMode(), the possibilities are:

  • Non connectable: Device is not connectable by others

  • Direct connectable: Device can be connected by only one node

  • Indirect connectable: Device can be connected by any node

Example:

{
    // Allow connections from everyone.
    BLE.setConnectableMode(BLE_GAP_UNDIRECTED_CONNECTABLE);
}

Advertising policy

It is also possible to define an advertising policy to configure if the module will answer to the scan requests and will allow connections for other devices. It is done with function setFiltering(). Four choices are possible:

  • All: Responds to scan requests from any master, allows connection from any master.

  • WhiteList scan: Responds to scan requests from whitelist only, allows connection from any master.

  • WhiteList connect: Responds to scan requests from any master, allows connection from whitelist only.

  • WhiteList all: Respond to scan requests from whitelist only, allows connection from whitelist only.

The setFiltering() function also allows defining scan policy and MAC filter, as discussed previously.

Example:

{
    /* Example where all present BLE modules are scanned, 
       but only whiteList members are allowed to conect. 
       Also MAC filter is enabled to produce one event per device.
    */
    BLE.setFiltering(BLE_GAP_SCAN_POLICY_ALL, BLE_GAP_ADV_POLICY_WHITELIST_CONNECT,
    BLE_MAC_FILTER_ENABLED);
}

TX power

Changes in the TX power will affect to the range of node advertisements. As described previously, it can be changed using the setTXPower()function.

Advertisement intervals and allowed channels

The time between advertisements can be also configured according to two parameters:

  • advertisement interval minimum

  • advertisement interval maximum

They are defined in units of 625 us, with a configurable range between 20 ms and 2.5 seconds. Default values are set to 320 ms.

On the other hand, the BLE standard uses three channels for advertising, which are 37, 38 and 39. The user can select which channel is used with a bitmask. For example, enable three channels with 7 (binary 0111), enable channels 37 and 39 with 5 (binary 0101) and so on.

If the module is advertising, any changes on these parameters will only take effect stopping advertising and start again.

Example of use:

{
    // setting advertisements each 100 ms on the three channels at same time
    BLE.setADVParameters(160,160,7);
}

Advertisement data structure

The maximum size of advertisement data is 31 bytes. This is the maximum size allowed by the Bluetooth 4.0 specification. The user can build the advertisement with a custom payload, but if compatibility with Bluetooth 4.0 specification is required, the data must be formatted according to the core specification. Visit the official Bluetooth SIG website for detailed information: www.bluetooth.org

Two types of advertisements can be configured on the BLE module: normal advertisements and scan responses. The normal advertisements are sent when the discoverable mode is different from non discoverable, in response to passive and active scans, while the scan response advertisements are sent only when an active scan is performed.

The advertisement data can be set using the function setAdvData(), specifying if normal advertisement or scan response is being modified, the data to place in the payload and its length. If the user introduces a data larger than allowed, advertisement data will not be set.

Example of use:

{
    // create an array to store adv data and fill it with user data.
    uint8_t data[31];
    // set normal advertisement data
    BLE.setAdvData(BLE_GAP_ADVERTISEMENT, data, 31);
    // set scan response data
    BLE.setAdvData(BLE_GAP_SCAN_RESPONSE, data, 31);
}

In the Waspmote Development section you can find a complete example about using this function.

Go to: https://development.libelium.com/ble-17-configuring-advertisements/

Last updated