PreviewPeripheral

open class PreviewPeripheral(scope: CoroutineScope, address: String = "00:11:22:33:44:55", name: String? = "My Device", type: PeripheralType = PeripheralType.LE, rssi: Int = -40, phy: PhyInUse = PhyInUse.PHY_LE_1M, state: ConnectionState = ConnectionState.Closed, services: ServerScope.() -> Unit = { Service(Service.GENERIC_ACCESS_UUID) { Characteristic( uuid = Characteristic.DEVICE_NAME, property = CharacteristicProperty.READ, permission = Permission.READ, ) Characteristic( uuid = Characteristic.APPEARANCE, property = CharacteristicProperty.READ, permission = Permission.READ, ) Characteristic( uuid = Characteristic.PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS, property = CharacteristicProperty.READ, permission = Permission.READ, ) } Service(Service.GENERIC_ATTRIBUTE_UUID) { Characteristic( uuid = Characteristic.SERVICE_CHANGED, property = CharacteristicProperty.INDICATE, permission = Permission.READ, ) } }, hasBondInformation: Boolean = false) : Peripheral

A preview implementation of Peripheral for Android.

This class is used to preview the UI in the Compose Preview.

Parameters

scope

The coroutine scope. This can be set to rememberCoroutineScope().

address

The MAC address of the peripheral.

name

An optional name of the peripheral.

type

The type of the peripheral, defaults to PeripheralType.LE.

rssi

The signal strength of the peripheral in dBm.

state

The connection state of the peripheral.

services

The list of fake services discovered on the peripheral.

hasBondInformation

true if the Android device has the bond information for the peripheral, that is, if the peripheral is bonded to the device. Defaults to false.

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope, address: String = "00:11:22:33:44:55", name: String? = "My Device", type: PeripheralType = PeripheralType.LE, rssi: Int = -40, phy: PhyInUse = PhyInUse.PHY_LE_1M, state: ConnectionState = ConnectionState.Closed, services: ServerScope.() -> Unit = { Service(Service.GENERIC_ACCESS_UUID) { Characteristic( uuid = Characteristic.DEVICE_NAME, property = CharacteristicProperty.READ, permission = Permission.READ, ) Characteristic( uuid = Characteristic.APPEARANCE, property = CharacteristicProperty.READ, permission = Permission.READ, ) Characteristic( uuid = Characteristic.PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS, property = CharacteristicProperty.READ, permission = Permission.READ, ) } Service(Service.GENERIC_ATTRIBUTE_UUID) { Characteristic( uuid = Characteristic.SERVICE_CHANGED, property = CharacteristicProperty.INDICATE, permission = Permission.READ, ) } }, hasBondInformation: Boolean = false)

Properties

Link copied to clipboard

MAC address of the peripheral as String, alias for Peripheral.identifier.

Link copied to clipboard
val bondState: StateFlow<BondState>

Returns the current bond state as StateFlow.

Link copied to clipboard

The current connection parameters as StateFlow.

Link copied to clipboard

Returns whether the system has bond information associated with this peripheral.

Link copied to clipboard
open override val identifier: String
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val name: String?
Link copied to clipboard
val phy: StateFlow<PhyInUse?>

The current PHY in use for transmitting and receiving data.

Link copied to clipboard
val state: StateFlow<ConnectionState>
Link copied to clipboard

The Bluetooth device type of the remote device.

Functions

Link copied to clipboard
suspend fun createBond()

Initiates bonding with the peripheral.

Link copied to clipboard
suspend fun disconnect()
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun maximumWriteValueLength(type: WriteType): Int

The maximum amount of data, in bytes, you can send to a characteristic in a single write operation.

Link copied to clipboard
suspend fun readPhy(): PhyInUse

Read the current transmitter PHY and receiver PHY of the connection.

Link copied to clipboard
suspend fun readRssi(): Int
Link copied to clipboard
suspend fun refreshCache()

Refreshes the cached GATT database associated with the peripheral and starts new service discovery automatically.

Link copied to clipboard
suspend fun removeBond()

Removes the bond information associated with the peripheral.

Link copied to clipboard

Requests new connection parameters.

Link copied to clipboard

Requests the highest possible MTU (ATT_MTU_MAX).

Link copied to clipboard
fun services(uuids: List<Uuid>): StateFlow<List<RemoteService>?>
Link copied to clipboard
suspend fun setPreferredPhy(txPhy: Phy, rxPhy: Phy, phyOptions: PhyOption): PhyInUse

Set the preferred connection PHY.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
suspend fun usingReliableWrite(operations: suspend ReliableWriteScope.() -> Unit)

Initiates a reliable write transaction for a given characteristic.