scanAndConnectToPeripheral

fun scanAndConnectToPeripheral(timeout: Long = 10000)

Connects to a BleTerminal device.

This function initiates the connection process by first validating the provided authKey and then scanning for available BLE devices. Upon finding a matching device, it establishes a connection and performs authentication.

Error Handling: The function returns a BleError in the following scenarios:

  • BleError.KeyNotFound: The authKey is not found.

  • BleError.KeyInvalid: The authKey has an invalid length (expected 64 characters).

  • BleError.BluetoothUnsupported: The device does not support Bluetooth.

  • BleError.BluetoothUnauthorized: Bluetooth permissions are not granted.

  • BleError.LocationUnauthorized: Location permissions are not granted (required for BLE scanning).

  • BleError.TerminalNotFound: Unable to find the target BleTerminal device.

Successful Connection: Upon successful connection and authentication, the BleListener.onTerminalConnected callback is invoked.

See also

Parameters

timeout

The duration to wait for a connection to be established.