BluetoothLowEnergy.ScanResult question

I have a question regarding the ScanResults from a BLE scan.

As of CIQ3.2 there is a new method called hasAddress() with the following description:

hasAddress(address) ⇒ Toybox.Lang.Boolean

           Check that advertised device BLE address matches

           Parameters:

           address — (Toybox.Lang.ByteArray, Toybox.Lang.String) —  Address to check for as a big-endian byte array or a string in the format "00:01:02:03:04:05"

Which is very good. However, what is not clear to me is how to read the address from the scan result in the first place.

I've tried to find this address in my apps in order to remember unambiguously the last BLE device that has been connected, but haven't  succeeded so far. (Eventually I used the advertised device name for the purpose, despite it is not guaranteed to be unique)

  • I asked about seeing the address back when BLE first came out, and if I recall, there was concern about security, in that an app could harvest ble mac addresses.

    One thing you can do, is once you get a scan result that's "good", you can persist that scan result - put it in Application.Storage - then after that, skip the scan and go right to pairing.  I do that in a number of my apps right now, and it really speeds up the process.

  • Thank you for your prompt response, Jim

    I haven't thought of this option. I'll try it.

    As I've mentioned, I'm using the device name now and it kind of works to find the last paired device among the visible scan results. However what I'm connecting to is an external sensor and if for example I put two of them switched on nearby, they both have the same name and it is not guaranteed which one will be picked for pairing.

    There's also a property RawData that I hoped to be unique, but it turned out that just as the device name, RawData content is one and the same on all units of the same sensor model.

  • You can use something like nRFConnect can see the BLE mac address, then use that to check the scan result.