0

Feather nRF52840: Bluefruit - How to use function setAddr?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather nRF52840: Bluefruit - How to use function setAddr?

by deep_kap on Sat Jan 23, 2021 12:58 pm

I want to change MAC address of BLE device during runtime.
I'm doing following steps, but getting error by calling setAddr function.
Here is my code section:
Code: Select all | TOGGLE FULL SIZE
Bluefruit.Advertising.stop();
Bluefruit.Advertising.clearData();
Bluefruit.ScanResponse.clearData();
connectionHandle = Bluefruit.connHandle();
connection = Bluefruit.Connection(connectionHandle);
delay(1000);
connection->disconnect();
delay(2000);

uint8_t mac[6] = {0};
uint8_t addr_type = Bluefruit.getAddr(mac);
Serial.print("Address Type: ");
Serial.println(addr_type);
for(int i = 0; i < 6; i++)
{
Serial.print(mac[i], HEX);
Serial.print(' ');
}
Serial.println();

ble_gap_addr_t* gap_addr;
gap_addr->addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
gap_addr->addr[0] = mac[0];
gap_addr->addr[1] = mac[1];
gap_addr->addr[2] = mac[2];
gap_addr->addr[3] = mac[3];
gap_addr->addr[4] = mac[4];
gap_addr->addr[5] = 0xCE;

if(Bluefruit.setAddr(gap_addr))
{
Serial.println("Addr change Done");
}
else
{
Serial.println("Addr change Error");
}

// Again start advertising

Bluefruit.setAddr() function return ZERO everytime.

Please guide me how to use setAddr function properly?

deep_kap
 
Posts: 2
Joined: Sat Aug 15, 2020 2:17 am

Re: Feather nRF52840: Bluefruit - How to use function setAdd

by danhalbert on Fri Feb 19, 2021 7:36 pm

`ble_gap_addr_t* gap_addr;` is a pointer to a `ble_gap_addr_t`. You need to declare an instance of that struct as `ble_gap_addr_t gap_addr`, without the `*`, and then get its address with `&gap_addr`. Right now gap_addr is probably 0.

There may be other issues, but let's start with that.

danhalbert
 
Posts: 2445
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.