BluetoothConnection

Properties

Link copied to clipboard

Indicates whether the connection is active

Link copied to clipboard
var mtu: Int

Indicates the connection MTU, default 23 Measured in Bytes

Link copied to clipboard

A list with all notifiable characteristics

Link copied to clipboard
var onConnect: EmptyCallback?

Called whenever a successful connection is established

Link copied to clipboard
var onDisconnect: EmptyCallback?

Called whenever a connection is lost

Link copied to clipboard

A list with all readable characteristics

Link copied to clipboard
var rsii: Int

Indicates the connection signal strength Measured in dBm

Link copied to clipboard

Holds the discovered services

Link copied to clipboard

Indicates whether additional information should be logged

Link copied to clipboard

A list with all writable characteristics

Functions

Link copied to clipboard
suspend fun close()

Closes the connection

Link copied to clipboard
fun observe(characteristic: String, interval: Long = 5000, owner: LifecycleOwner? = null, callback: OnCharacteristicValueChangeCallback<ByteArray>)

Observe a given characteristic

Link copied to clipboard
fun observeString(characteristic: String, interval: Long = 5000, owner: LifecycleOwner? = null, charset: Charset = Charsets.UTF_8, callback: OnCharacteristicValueChangeCallback<String>)

Observe a given characteristic

Link copied to clipboard
suspend fun read(characteristic: String): ByteArray?
suspend fun read(characteristic: String, charset: Charset = Charsets.UTF_8): String?

Performs a read operation on a specific characteristic

Link copied to clipboard
fun readAsync(characteristic: String, callback: (ByteArray?) -> Unit)
fun readAsync(characteristic: String, charset: Charset, callback: (String?) -> Unit)

Performs a read operation on a specific characteristic

Link copied to clipboard

Requests a read of the RSSI value, which is updated on the rsii variable

Link copied to clipboard
fun requestMTU(bytes: Int): Boolean

Request a MTU change Note: even if this method returns true, it is possible that the other device does not accept it, so Android will fallback to the previous negotiated MTU value. This will be reflected by the mtu variable.

Link copied to clipboard
fun stopObserving(characteristic: String)

Stops observing the characteristic

Link copied to clipboard
fun write(characteristic: String, message: ByteArray): Boolean
fun write(characteristic: String, message: String, charset: Charset = Charsets.UTF_8): Boolean

Performs a write operation on a specific characteristic