2. Setting the Bluetooth Address and Device Name¶
The SmartBond™ device family uses a default Bluetooth Device (BD) address if the device developer has not assigned a specific address. This approach allows a device to be brought up quickly but proves inadequate as soon as multiple devices advertise using the same address. This section provides a step-by-step description of how to change the BD address and device name. It also explains the key parameters.
2.1. Importing a Project¶
The fastest way to get started with advertising is to examine the example application named
ble_adv
from our SDK. The first step is to include the project in our current workspace:
In the SmartSnippet Welcome page, click Browse in the SOFTWARE RESOURCES section.
2. In the pop-up window, click OK as your current workspace folder should be automatically selected. If this is not the case, you must explicitly select it.
The final step is to select the preferred project(s) to import in. By default all projects are selected. It is recommended to:
Click Deselect All.
Select the required projects by clicking on the respective tick box.
Click Finish.
Now you are ready to start working with the project.
2.2. Setting the BD Address¶
2.2.1. Using MACRO Definition¶
To change the BD address, follow the method in Using API Functions.
When no address is provided, the application uses the default address definition found in the
/sdk/ble/config/ble_config.h
header file. It is not recommended to change this definition although, for some
development purposes, it can be more practical than programming the address through the API. If possible, define
the proper macro definition in the /ble_adv/config/custom_config_qspi.h
header file which is where all custom
definitions should be declared.
Code snippet:
/*
* Add this macro definition in custom_config_qspi.h header file to overwrite the
* default public address. The address will be displayed in reverse order i.e. 06-05-04-03-02-01
*/
#define defaultBLE_STATIC_ADDRESS {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}
Note
The address in the above macro definition is the PUBLIC address. It is used if the user does not explicitly declare a custom address as described in Using API Functions.
2.2.2. Using API Functions¶
The recommended way of setting the device address is to use the GAP function which is responsible for setting the BD address.
Step #1 Add the following code snippet somewhere near the beginning of the main.c
file.
Code snippet:
/*Initialize the BLE structure related to BD address value*/
static const own_address_t user_bd_address = {
.addr_type = PRIVATE_STATIC_ADDRESS,
.addr = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}
};
Note
The device address type must be set to PRIVATE_STATIC_ADDRESS
.
If this is not done, the default BD address is used (see Using MACRO Definition).
Enumeration Name |
Value |
Description |
---|---|---|
PUBLIC_STATIC_ADDRESS |
0x0 |
Public Static Address |
PRIVATE_STATIC_ADDRESS |
0x1 |
Private Static Address |
PRIVATE_RANDOM_RESOLVABLE_ADDRESS |
0x2 |
Private Random Resolvable Address |
PRIVATE_RANDOM_NONRESOLVABLE_ADDRESS |
0x3 |
Private Random Non-resolvable Address |
Step #2 Call the corresponding GAP function to set the BD address with the defined value. (Place it immediately after the device name function.)
Code snippet:
/*Set BD address to the preferred value*/
ble_gap_address_set(&user_bd_address, 0x00FF);
Note
The second input parameter of this function, that is 0x00FF, does not have any
special meaning. It is only used if the address type is either
PRIVATE_RANDOM_RESOLVABLE_ADDRESS
or PRIVATE_RANDOM_NONRESOLVABLE_ADDRESS
.
2.3. Setting the Device Name¶
Open the main.c
file in the ble_adv
folder and change the device name as required.
Code snippet:
/* Set device name */
ble_gap_device_name_set("Dialog TTT Demo", ATT_PERM_READ);
Enumeration Name |
Value |
Description |
---|---|---|
ATT_PERM_NONE |
0x00 |
Your are not permitted to take any action |
ATT_PERM_READ |
0x01 |
You are permitted Read only action |
ATT_PERM_WRITE |
0x02 |
You are permitted Write only action |
ATT_PERM_READ_AUTH |
0x04 |
You are permitted Read only action using authentication |
ATT_PERM_WRITE_AUTH |
0x08 |
You are permitted Write only action using authentication |
ATT_PERM_READ_ENCRYPT |
0x10 |
You are permitted Read only action using encryption |
ATT_PERM_WRITE_ENCRYPT |
0x20 |
You are permitted Read only action using encryption |
ATT_PERM_KEYSIZE_16 |
0x80 |
Using Keysize 16 |
ATT_PERM_RW |
ATT_PERM_READ | ATT_PERM_WRITE |
You are permitted both Read and Write action |
ATT_PERM_RW_AUTH |
ATT_PERM_READ_AUTH | ATT_PERM_WRITE_AUTH |
You are permitted both Read and Write action using authentication |
ATT_PERM_RW_ENCRYPT |
ATT_PERM_READ_ENCRYPT | ATT_PERM_WRITE_ENCRYPT |
You are permitted both Read and Write action using encryption |