MonitoringAndDiagnosticsConnection

class MonitoringAndDiagnosticsConnection : Log.IdentifiableEmitter<String>

A helper class that connects to a remote Bluetooth LE device using a CentralManager, and attaches MonitoringAndDiagnosticsProfile to it once connected.

This class owns the whole connection lifecycle: connecting, auto-reconnecting, and monitoring the bond state. Use it either:

  • with an existing CentralManager and Peripheral, e.g. a mock manager for testing, or one that isn't otherwise connected by the application, or

  • with a NativeAndroidEnvironment and a BluetoothDevice, for applications don't yet use Kotlin BLE Library.

Applications that already connect and manage their own Peripheral elsewhere should instead attach MonitoringAndDiagnosticsProfile directly to it, and don't need this class.

See also

Constructors

Link copied to clipboard
constructor(centralManager: CentralManager, peripheral: Peripheral, scope: CoroutineScope)

Creates a new instance of MonitoringAndDiagnosticsConnection with the given CentralManager and Peripheral.

constructor(environment: NativeAndroidEnvironment, bluetoothDevice: BluetoothDevice, scope: CoroutineScope)

Creates a new instance of MonitoringAndDiagnosticsConnection with the given NativeAndroidEnvironment and BluetoothDevice.

Types

Link copied to clipboard
sealed class State

Represents the state of the device Bluetooth LE connection.

Properties

Link copied to clipboard
val chunks: SharedFlow<ByteArray>

A flow of streamed data received from the device.

Link copied to clipboard
open override val identifier: String

The MAC address of the associated Peripheral.

Link copied to clipboard
var logger: Log.Sink<Category>?

The log sink for events produced by this connection and the attached MonitoringAndDiagnosticsProfile.

Link copied to clipboard

The Monitoring & Diagnostics Service profile, exposing no.nordicsemi.android.observability.data.ChunksEmitter.state and no.nordicsemi.android.observability.data.ChunksEmitter.chunks, decoupled from this connection.

Link copied to clipboard

The current state of the device, including the Bluetooth LE connection.

Functions

Link copied to clipboard
fun close()

Closes the open connection.

Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.d(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.d(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.debug(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.debug(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.e(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.e(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.error(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.error(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.i(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.i(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.info(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.info(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open override fun <C : Log.Category> Log.Sink<C>.log(category: C, level: Log.Level, throwable: Throwable)
open override fun <C : Log.Category> Log.Sink<C>.log(category: C, level: Log.Level, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open override fun <C : Log.Category> Relay(sink: () -> Log.Sink<C>?): Log.Sink<C>
Link copied to clipboard
fun start()

Starts the connection to the device and begins observing the Monitoring & Diagnostics Service.

Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.t(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.t(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.trace(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.trace(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.v(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.v(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.verbose(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.verbose(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.w(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.w(category: C, throwable: Throwable?, message: () -> String)
Link copied to clipboard
open fun <C : Log.Category> Log.Sink<C>.warn(category: C, throwable: Throwable)
open fun <C : Log.Category> Log.Sink<C>.warn(category: C, throwable: Throwable?, message: () -> String)