bt_adv_addr_get()
Description
Reads the address the user advertising set is on air with and stores it into the provided array, most significant byte first. The user set is the one bt_adv_config(), bt_adv_data_set() and bt_adv_start() drive. The connectable set started by bt_adv_conn_start() is not covered.
Syntax
bt_adv_addr_get(mac_addr[], size = sizeof mac_addr);
Parameters
Variable | Input |
| The address is stored in this array, most significant byte first. It must hold at least 6 cells. |
| Size of |
Returns
Return value | Return explanation |
SCRIPT_OPERATION_SUCCESS | Successfully read the advertising address. |
SCRIPT_OPERATION_FAILED | The user advertising set does not exist yet: none of |
SCRIPT_PARAM_INVALID |
|
SCRIPT_NO_ACCESS | Bluetooth is not initialized (before |
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];
new adv_addr[MAC_ADDR_SIZE] = [0];
main()
{
bt_init();
bt_adv_config(BT_ADV_OPT_NONE, BT_GAP_ADV_INT_FAST_MIN_2, BT_GAP_ADV_INT_FAST_MAX_2);
bt_adv_data_set(demo_adv_array, sizeof(demo_adv_array));
bt_adv_start();
bt_adv_addr_get(adv_addr);
for(;;)
{
Delay(100);
}
}Notes and Warnings
Not in XDM yet: XDM's bluetooth include declares bt_adv_addr_get from the next XDM release on. Until then a script has to declare it itself, under another name so that it still compiles once the include declares it, for example native adv_addr_get(mac_addr[], size = sizeof mac_addr) = bt_adv_addr_get;, and call adv_addr_get().
Read the address after bt_adv_start(). Without BT_ADV_OPT_USE_IDENTITY, the set advertises on a random address that changes on every bt_adv_config() and every bt_adv_start(), so an address read between the two is never advertised. With BT_ADV_OPT_USE_IDENTITY, it is the device's identity address, the one bt_mac_address_get() returns.
After bt_adv_stop() the function still succeeds and returns the address the set last advertised on.