Seeed-Studio / Seeed_Arduino_rpcBLE

A library of maximum ESP32 BLE-compatible software.
MIT License
10 stars 6 forks source link

BLEAddress::toString() reversed mac address #4

Open requiembkp opened 3 years ago

requiembkp commented 3 years ago

WIO TERMINAL

My bluetooth beacons mac address is: c2:79:04:1a:58:2a (RUUVITAG)

BLEScanResults foundDevices = pBLEScan->start(scanTime, false); for (int i=0; i<foundDevices.getCount(); i++) { oneDevice = foundDevices.getDevice(i);
Serial.println(oneDevice.getAddress().toString().c_str()); }

Print result: 2a:58:1a:04:79:c2

Temporary fix:

BLEAddress.cpp

std::string BLEAddress::toString() { auto size = 18; char res = (char)malloc(size); snprintf(res, size, "%02x:%02x:%02x:%02x:%02x:%02x", m_address[5], m_address[4], m_address[3], m_address[2], m_address[1], m_address[0]); std::string ret(res); free(res); return ret; } // toString

Chunchun-tian commented 3 years ago

The MAC address is reversed. For example, if the MAC of the device is 52: C0: 4E: 22:23:24, the code will reverse uint8 t bd addr[6] = {0x24, 0x23, 0x22, 0x4e, 0xc0, 0x52};