If you need to create a connection with a Bluetooth LE device

For a bluetooth project with Xamarin (Android API 21 and above), I would like to know if creating a connection with a Bluetooth device is normal. Current requirements:

  • A Bluetooth device is used often but not constantly.
  • Reconnecting should be as fast as possible.
  • The Bluetooth address changes randomly when the device is turned off.
  • Device name unknown, blank or random
  • The connection is encrypted.
  • The connection uses an overlying API, for which a Bluetooth device is required as a parameter for the connection.

You should create a connection with this device for "better" recognition (as a kind of cache) or reconnect to the device from scratch. What is common in this scenario? So, this is not the question “Can I fasten”, but whether it is necessary to bind or even better: what is the corrective and the working, reliable script.

I am currently using code like this (result.Device.Name is for dev purposes):

  public override void OnScanResult([GeneratedEnum] ScanCallbackType callbackType, ScanResult result)
    {

        if (result.Device.Name == "  " &&

            !_discovered &&
          result.ScanRecord != null &&
          result.ScanRecord.ServiceUuids != null &&
          result.ScanRecord.ServiceUuids.Any(x => x.Uuid.ToString().ToUpper() == uuid))
        {
            lock (_locker)
            {
                _discovered = true;
                _deviceList.Add(result.Device);
                BluetoothDiscoverySucces?.Invoke(result.Device);
            }
        }
    }
+6
source share
1 answer

: , - . , , . , , . / Bluetooth .


: Bluetooth Bluetooth-. , / ( , .)

Bluetooth Low Energy / : -

1 -

- (, ), (, ) .

2 -

, ( LESC-, ).

3 -

, CSRK ( ), IRK (Identity Resolving Key) .

IRK . Bluetooth v4.0, , LE Privacy, , . , , . , /. IRK, Bluetooth.


, : -

  • Bluetooth , .

/ , (.. ). , / .

- . , , . .

  • Bluetooth , .

, LE. .

  • ,

BLE. . , , .

( 3 ). , , , .

  • API, Bluetooth .

, , .


" Bluetooth 5.0", 3, H, 2 " " (. 2295)

+12

Source: https://habr.com/ru/post/1015843/


All Articles