3. Changing Advertising Parameters

This section describes how to change the advertising parameters. It covers all the necessary key elements related to advertising, specifically dealing with advertising data and intervals. It also describes the advertising channel map and mode.

3.1. Advertising Data

Step #1Change the contents of the existingadv_data[]variable for the required advertising data.

Code snippet:

/*Bluetooth low energy adv demo advertising data*/staticconstuint8_tadv_data[]={0x14,GAP_DATA_TYPE_LOCAL_NAME,'H','o','w',' ','A','r','e',' ','Y','o','u',' ','T','o','d','a','y',' ','?'};

Note

The first element of the array is the size of the data to be sent plus an extra null character, that is,19 + 1 = 20elements or 0x14 in hexademical format. If the wrong value is given, it is likely that Bluetooth low energy device will not advertise at all so care must be taken when calculating this value.


3.2. Advertising Interval

Step #2The advertising interval is the period for which a Bluetooth low energy peripheral device advertises. For this scenario we have adapted two different time slots - one in a high-speed mode and another at a lower speed. To switch between them, set the preferred mode to “1”.

Code snippet:

/* Depending on the advertising interval mode, the corresponding code segment is selected */#if (FAST_ADV_INTERVAL == 1)staticconstuint16_tmin=BLE_ADV_INTERVAL_FROM_MS(80);staticconstuint16_tmax=BLE_ADV_INTERVAL_FROM_MS(100);#elsestaticconstuint16_tmin=BLE_ADV_INTERVAL_FROM_MS(1000);staticconstuint16_tmax=BLE_ADV_INTERVAL_FROM_MS(1500);#endif

Table 3 Advertising Intervals

MACRO

Value

Description

FAST_ADV_INTERVAL

0x0

Fast advertising mode.

POWER_ADV_INTERVAL

0x1

Slow advertising mode. Use this mode for a reduced power consuption.


Step #3Call the corresponding GAP function to set the min-max advertising intervals (before starting advertising and after starting the Bluetooth low energy module as a peripheral device).

Code snippet:

/*Set advertising interval*/ble_gap_adv_intv_set(min,max);

3.3. Advertising Channel Map

Step #4The channel defined in theBluetooth Core Specificationconsists of 37 data communication channels and 3 advertising channels used for device discovery. The latter are allocated in different parts of the spectrum to prevent interference from concurrent activities in theISM Band. Specifically a Bluetooth low energy device can advertise on channels 37, 38, and 39 which correspond to frequencies of 2.402 MHz, 2.2426 MHz, and 2.480 MHz respectively. SmartBond™ devices advertise successively in all enabled channels. By default, all channels are enabled. To force the Bluetooth low energy device to use only one channel, for example channel 37, use the following GAP function:

Code snippet:

/* Set advertising channel map */gap_adv_chnl_tchannel_map=GAP_ADV_CHANNEL_37;ble_gap_adv_chnl_map_set(channel_map);

Table 4 Advertising Channels

Enumeration Name

Value

Description

GAP_ADV_CHANNEL_37

0x00

Select channel 37 for advertising

GAP_ADV_CHANNEL_38

0x02

Select channel 38 for advertising

GAP_ADV_CHANNEL_39

0x04

Select channel 39 for advertising

3.4. Advertising Mode

Step #5The advertising mode is customizable by changing the input parameter of theble_gap_adv_start()function. The default mode in this application is depicted in the following code snippet and forces the Bluetooth low energy module to advertise toward all devices in the outside world.

Code snippet:

/* Start advertising */ble_gap_adv_start(GAP_CONN_MODE_UNDIRECTED);

Table 5 Advertising Modes

Enumeration Name

Value

Description

GAP_CONN_MODE_NON_CON

0x00

The Bluetooth low energy device advertises without permitting a connection to another central device.

GAP_CONN_MODE_UNDIRECTED

0x01

The Bluetooth low energy device advertises towards all devices regardless of their BD value.

GAP_CONN_MODE_DIRECTED

0x02

The Bluetooth low energy device advertises towards a device with a specific BD address.

GAP_CONN_MODE_DIRECTED_LDC

0x03

The Bluetooth low energy device advertises towards a device with a specific BD address using Low Duty Cycle.