esp-nimble-cpp
esp-nimble-cpp copied to clipboard
`advertisedDevice->getAddress().getNative()` Returns MAC Address in Reverse Order
Not sure if this intentional.
Example Code:
NimBLEScan *pBLEScan;
class MyAdvertisedDeviceCallbacks : public NimBLEAdvertisedDeviceCallbacks
{
void onResult(NimBLEAdvertisedDevice *advertisedDevice)
{
// // local variables from bluetooth scan
uint8_t blueRSSI = (uint8_t)advertisedDevice->getRSSI();
uint8_t blueMAC_0 = advertisedDevice->getAddress().getNative()[5];
uint8_t blueMAC_1 = advertisedDevice->getAddress().getNative()[4];
uint8_t blueMAC_2 = advertisedDevice->getAddress().getNative()[3];
uint8_t blueMAC_3 = advertisedDevice->getAddress().getNative()[2];
uint8_t blueMAC_4 = advertisedDevice->getAddress().getNative()[1];
uint8_t blueMAC_5 = advertisedDevice->getAddress().getNative()[0];
// MAC will be in the correct order as we went in reverse.
Serial.printf("%X:%X:%X:%X:%X:%X\n", blueMAC_0, blueMAC_1, blueMAC_2, blueMAC_3, blueMAC_4, blueMAC_5);
}
}
This is the way it is represented by the NimBLE stack, thus it is the "native" address. Unfortunately this does cause some confusion for users occasionally.