h2zero / NimBLE-Arduino

A fork of the NimBLE library structured for compilation with Arduino, for use with ESP32, nRF5x.
https://h2zero.github.io/NimBLE-Arduino/
Apache License 2.0
670 stars 138 forks source link

NimBLEscan turn a wrong MAC adress by 2 in the last octet #628

Closed kbaggen closed 5 months ago

kbaggen commented 6 months ago

Hi, I ran into an issue where when I scan by my ESP32 DevKit the MAC-id is shown wrongly, e.g. it seems the BLEscan adds +2 to the last octet.

The issue seems to be reported at this link --> https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html#mac-address

The code for this area:

BLEScanResults foundDevices = pBLEScan->start(SCAN_TIME);
  deviceCount = foundDevices.getCount();
  Serial.print(deviceCount);
  Serial.println(F(" Devices Found."));
  pBLEScan->stop();
  BLEDevice::deinit(0);

  for (uint32_t i = 0; i < deviceCount; i++)
  {
    BLEAdvertisedDevice Device = foundDevices.getDevice(i);
    String DevString, DevData, DevRapt;
    DevString = Device.toString().c_str();
    DevData = DevString.substring(63);
MAC_data = Device.getAddress().toString().c_str(); 
    Serial.println(MAC_data);
}

Returns --> 78:e3:6d:3d:11:7e Where the correct should be --> 78:e3:6d:3d:11:7c

I am in doubt what to do to get over this? I tried both NimBLEDevice.h and BLEDevice.h, and both seems to do the same error by 2 chippers!

Klaus

h2zero commented 6 months ago

The MAC address you are receiving is the correct BLE address. The MAC it seems you are looking to get is the esp32 base MAC, which the BLE stack will have no knowledge of.

kbaggen commented 5 months ago

ok, I solved by just disregards the last ciffer, hence, I close it :-)