0

nrf52840 getPeerAddr Function
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

nrf52840 getPeerAddr Function

by kwohman on Mon Feb 22, 2021 4:48 pm

I'm writing a program where it's necessary to identify which device has connected to the nrf52840 Feather Express in peripheral mode. Is it possible to identify a connected host/central iOS device by it's MAC address via any of the Bluefruit functions?

I have modified the peripheral -> bleuart example sketch as shown below, trying a number of different methods to call getPeerAddr. So far, I can get a series of hex numbers, and they are consistent each time that a device connects (however, none match the Bluetooth MAC address in the iOS devices settings page. also - they change each time that airplane mode is cycled, or the device is hard reset).

I'm probably using the functions incorrectly, but have run out of documentation / posts to search / experience.

Code: Select all | TOGGLE FULL SIZE
// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{
  // Get the reference to current connection
  BLEConnection* connection = Bluefruit.Connection(conn_handle);

  char central_name[32] = { 0 };
  connection->getPeerName(central_name, sizeof(central_name));

  Serial.print("Connected to ");
  Serial.println(central_name);

  uint8_t nrfMAC[6] = {0,0,0,0,0,0};

  Bluefruit.getAddr(nrfMAC);

  Serial.printf("%02X:%02X:%02X:%02X:%02X:%02X %s\n", nrfMAC[5], nrfMAC[4], nrfMAC[3], nrfMAC[2], nrfMAC[1], nrfMAC[0], "nrf52480 MAC");

//  Bluefruit.getPeerAddr(nrfMAC);                                   
//  ^^ fails compile with: 'class AdafruitBluefruit' has no member named 'getPeerAddr'; did you mean 'getAddr'?
 
  connection->getPeerAddr();
  ble_gap_addr_t gap_addr;
// ^^ gets some numbers, but seems to change when bluetooth cycled on target device.

  Serial.printf("%02X:%02X:%02X:%02X:%02X:%02X %s\n", gap_addr.addr[5], gap_addr.addr[4], gap_addr.addr[3], gap_addr.addr[2], gap_addr.addr[1], gap_addr.addr[0], "gap_addr.addr numbers");

//  connection->getPeerAddr(nrfMAC);                                 
//  ^^ fails compile with:  /Library/Arduino15/packages/adafruit/hardware/nrf52/0.21.0/libraries/Bluefruit52Lib/src/BLEConnection.h:85:20: note:   candidate expects 0 arguments, 1 provided

//  Bluefruit.printInfo();                                             //  works, prints all info for the nrf52480
 
}



Below is output from the Serial Monitor from connections with a few iOS devices:

Code: Select all | TOGGLE FULL SIZE
Connected to iPhone
D5:9B:50:70:EE:F3 nrf52480 MAC
71:B9:57:14:5F:63 gap_addr.addr numbers
Disconnected, reason = 0x13

Connected to iPad
D5:9B:50:70:EE:F3 nrf52480 MAC
57:A8:1C:64:A7:49 gap_addr.addr numbers
Disconnected, reason = 0x13

Connected to MacBook Air
D5:9B:50:70:EE:F3 nrf52480 MAC
18:3E:EF:E8:F1:E7 gap_addr.addr numbers
Disconnected, reason = 0x13

Connected to iPhone
D5:9B:50:70:EE:F3 nrf52480 MAC
71:B9:57:14:5F:63 gap_addr.addr numbers
Disconnected, reason = 0x13

<— Here I went to airplane mode and back on the iPhone and the iPhone address numbers changed —>

Connected to iPhone
D5:9B:50:70:EE:F3 nrf52480 MAC
40:69:DC:DF:57:F6 gap_addr.addr numbers
Disconnected, reason = 0x13

Connected to iPad
D5:9B:50:70:EE:F3 nrf52480 MAC
57:A8:1C:64:A7:49 gap_addr.addr numbers
Disconnected, reason = 0x13

<— Here I went to airplane mode and back on the iPad and the iPad address numbers changed —>

Connected to iPad
D5:9B:50:70:EE:F3 nrf52480 MAC
59:90:AD:D9:9D:BF gap_addr.addr numbers
Disconnected, reason = 0x13

Connected to iPhone
D5:9B:50:70:EE:F3 nrf52480 MAC
40:69:DC:DF:57:F6 gap_addr.addr numbers
Disconnected, reason = 0x13

Connected to iPad
D5:9B:50:70:EE:F3 nrf52480 MAC
59:90:AD:D9:9D:BF gap_addr.addr numbers
Disconnected, reason = 0x13

None of these match the settings screen for the iPad or iPhone Bluetooth MAC address.


Thanks in advance for any help. Using Arduino IDE 1.8.13, nrf52480 bsp 0.21.0, iOS 14.4, Bluefruit Connect 3.6.2. Data from Bluefruit.printInfo() below:

Code: Select all | TOGGLE FULL SIZE
--------- SoftDevice Config ---------
Max UUID128     : 10
ATTR Table Size : 4096
Service Changed : 1
Peripheral Connect Setting
  - Max MTU         : 247
  - Event Length    : 100
  - HVN Queue Size  : 3
  - WrCmd Queue Size: 1

--------- BLE Settings ---------
Name            : Bluefruit52
Max Connections : Peripheral = 1, Central = 0
Address         : D5:9B:50:70:EE:F3 (Static)
TX Power        : 4 dBm
Conn Intervals  : min = 20.00 ms, max = 30.00 ms
Conn Timeout    : 2000 ms
Peripheral Paired Devices:

kwohman
 
Posts: 2
Joined: Sat Jul 18, 2020 9:00 pm

Re: nrf52840 getPeerAddr Function

by jevada on Tue Feb 23, 2021 5:45 pm

The mac address of your iPhone changes every time it wakes up - by design. It is part of the security measures built in BLE: the change is there to make sure you cannot track a device based on its address.

Based on the mac address examples you write down, apple uses what is known as a Random Static Address (as do most devices really). The standard says the address could either be unchanged during the lifetime of a product or it can change "at boot time". It seems apple randomizes the address each time the stack is restarted or initialized. Standard healthy behavior I'm afraid.

jevada
 
Posts: 163
Joined: Fri Dec 15, 2017 5:29 am

Re: nrf52840 getPeerAddr Function

by kwohman on Tue Feb 23, 2021 6:05 pm

Thanks very much for the reply. After a few nights of experimentation it seemed that it might be the case that the iOS devices were assigning random addresses. Interesting that the laptop doesn't, it's BLE MAC seems fixed.

I'm using the Bluefruit Connect App for the iOS devices - just wish there was some way to identify a specific device without having the user have to send a string or otherwise. Would like them to just be able to select the nrf52840 and then the rest be automatic (without having to write my own adaptation of the Swift Terminal App).

kwohman
 
Posts: 2
Joined: Sat Jul 18, 2020 9:00 pm

Re: nrf52840 getPeerAddr Function

by jevada on Sun Feb 28, 2021 8:50 am

I don't get it really. Why do you need to know to which central you are connected on the nRF52840?

jevada
 
Posts: 163
Joined: Fri Dec 15, 2017 5:29 am

Please be positive and constructive with your questions and comments.