Skip to content

Notice about BLE Address comparisons #777

Open
@h2zero

Description

@h2zero

I'm seeing a trend in the issues since the mistaken and soon to be removed release of version 2.0.0 on the Arduino library manager where the address comparisons that were working are now not, so I will explain why here.

BLE has what is referred to as address types, there are public, random static, random resolvable private, and non-resolvable private addresses.

For the purpose of this post we only need to know that there are 2 types of concern when devices are advertising public; type = 0 and random; type = 1.

The BLE specification says:

Whenever two device addresses are compared, the comparison shall include the device address type (i.e. if the two addresses have different types, they are different even if the two 48-bit addresses are the same).

So, what changed?

Prior to version 2, the address type was not compared and so a device with a random (type 1) address 11:22:33:44:55:66 would return equal to a device with a public (type 0) address 11:22:33:44:55:66 which as stated in the specification would be incorrect.

How to fix it?

If you are scanning for a specific device by address you will need to set the type when you create the address, this is done by providing the type parameter to the constructor: NimBLEAddress myAddress("11:22:33:44:55:66", **TYPE; 0 or 1**);

How to find the address type?

When scanning you can get the address type from the advertised device through either NimBLEAdvertisedDevice::getAddressType() or from the address itself NimBLEAddress::getType().

Hope this helps, post any questions below.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions