Alter MAC Address in Arduino BLE sense packets

Is it possible to set the address of an Arduino BLE sense device? ie. the value that is returned here:

String address = BLE.address();

  Serial.print("Local address is: ");
  Serial.println(address);

For more context, I have an unusual use case where I need the advertising packets from two separate Arduino Nano 33 BLE devices to be bit for bit identical.

So far I'm doing this on each:

  BLE.setLocalName("Unit 1");
  BLE.setDeviceName("Unit 1");
  byte data[5] = { 0x01, 0x02, 0x03, 0x04, 0x05};
  BLE.setManufacturerData(data, 5);

However, unless I can change the device address on each to be the same then I think the advertising packets will still differ (please correct me if I'm wrong on this).

Any help or insights into this would be appreciated.

Thanks,
Rich.

Welcome to the forum.

If you read the Bluetooth Specification (link below), you will find that the specification requires each Bluetooth device to have a unique 48-bit Bluetooth device address (BD_ADDR).

So, your use case would violate the Bluetooth specification.

Furthermore, when you look at the Bluetooth architecture you can see that there is a interface called the HCI (Host Controller Interface) that separates the stack into two parts. This can be two physical chips but is also used as pure logical interface when the entire BLE stack is on one chip. The ArduinoBLE library at the lowest level talks trough the HCI to the BLE controller. HCI has a function to read the BD_ADDR (HCI_Read_BD_ADDR) but there is no function to set it to a value chosen by you. You can find the function in the HCI.cpp file.

int HCIClass::readBdAddr(uint8_t addr[6])

There are ways to allow the BLE controller to generate a random address but that would not create the same address on two different chips. This is used to prevent tracking of BLE devices e.g., by all modern smartphones by changing the address in a random interval. I do not know whether this function is implemented in the ArduinoBLE library. You would have to look trough the low level part of the library.

Can you describe your use case in a bit more detail? Maybe we can come up with an alternative solution.

1 Like

Thanks Klaus for your detailed response, that's really helpful.

I'm collecting data for a research project that is trying to demonstrate that it is possible to identify the piece of hardware that transmitted a bluetooth packet even if the packets are identical (or contain no fixed identifying data).

We are intercepting the data using a software defined radio and feeding the raw signal to a deep learning model.

Of course having a fixed mac address makes the problem trivial for the model to identify the device.

However, if it's not possible to explicitly set the address, randomly changing the address for each packet would have the same effect (the AI wouldn't be able to rely on simply reading the address).

I'll see if I can find a way to do this.