NimBLE-Arduino icon indicating copy to clipboard operation
NimBLE-Arduino copied to clipboard

Getting different MAC address of the same device.

Open HeavyShmel opened this issue 3 years ago • 2 comments
trafficstars

I'm trying to make a dynamic whitelist on esp32.

To do it, I store the addresses of devices with which I had a connection in NVS. If esp32 have a reboot, it retrieve addresses from the NVS and add them to the Whitelist.

But I ran into a problem. The smartphone from which I connect to the device almost every time has a different MAC address. And I get the same problem with other smarphone. And I have never got a real MAC address of my smartphone on esp32. So what could be a reason?

I use this server callback in which I get an address of smartphone:

void ServerCallbacks::onConnect(NimBLEServer *pServer, ble_gap_conn_desc *desc) { NimBLEAddress tmp(desc->peer_ota_addr); if(!NimBLEDevice::onWhiteList(tmp)){ NimBLEDevice::whiteListAdd(tmp); addAddressToNVS(tmp); //my function in whitch i save an address } pAdvertising->stop(); }

HeavyShmel avatar Oct 20 '22 14:10 HeavyShmel

Phones use a random resolvable address. You would need to bond with the phone to be able to recognize it when the address changes and retrieve its static address.

h2zero avatar Oct 20 '22 15:10 h2zero

Sorry to reply to this very old thread, but I seem to have the exact same issue.

Although my device is bonding, how would I get the static address? According to https://github.com/h2zero/NimBLE-Arduino/blob/release/1.4/examples/NimBLE_Server_Whitelist/NimBLE_Server_Whitelist.ino

That would be desc->peer_ota_addr but that is not correct, since that address is always changing.

sanastasiou avatar Jun 07 '23 09:06 sanastasiou

the desc->peer_id_addr would be what is needed. But this has changed going forward.

h2zero avatar Jun 04 '24 21:06 h2zero