bt_adv_conn_data_set()
Description
Sets data to advertise with a pre-configured advertisement configuration for connectable advertising. Data is added to the advertising indication packet in the connectable advertising set. This does not override device name in GATT server settings, which is advertised in the scan response packet.
Syntax
bt_adv_conn_data_set(adv_data[], data_len);
Parameters
Variable | Input |
|---|---|
| An array of data to advertise. |
| Length of the data to be advertised. |
adv_data - provide advertised data array in the following format: {data_type_length, data_type, data}. The provided document can be used to find more details on existing data types.
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Successfully added advertisement data. |
SCRIPT_OPERATION_FAILED | Failed to add advertisement data. |
SCRIPT_PARAM_INVALID | Given data length is bigger than data array. |
SCRIPT_NO_ACCESS | This error signifies that Bluetooth communication was not initialized. |
Example
Example of making advertised data array
To create custom advertised data, you would need to select the data type you want to advertise. For instance, if you want to advertise specific "Service data" and "Manufacturer specific data," you would use the data types 0x16 and 0xFF respectively, as indicated in the document:
As an example, we'll add data for these data types:
For data type 0x16 (Service data), we'll advertise: 0x09, 0x6C.
For data type 0xFF (Manufacturer specific data), we'll advertise: 0xAB, 0x41, 0x30.
So newly formed array would look like this = {0x03, 0x16, 0x09, 0x6C, 0x04, 0xFF, 0xAB, 0x41, 0x30}
where:
0x03 - length of upcoming data type (in this case it’s 3 bytes 0x16, 0x09 and 0x6C)
0x16 - Data type (Service data)
0x09 - Data
0x6C - Data
0x04 - length of upcoming data type (In this case it’s 4 bytes 0xFF, 0xAB, 0x41 and 0x30)
0xFF - Data type (Manufacturer specific data)
0xAB - Data
0x41 - Data
0x30 - Data
Function call example
#include <io>
#include <read>
#include <float>
#include <string>
#include <core>
#include <write>
#include <define>
#include <socket>
#include <bluetooth>
new demo_adv_array[9] = [0x03, 0x16, 0x09, 0x6C, 0x04, 0xFF, 0xAB, 0x41, 0x30];
main()
{
bt_init();
/* GATT server init code start */
/* GATT server init code end */
bt_adv_conn_data_set(demo_adv_array, sizeof(demo_adv_array));
for(;;)
{
Delay(100);
}
}