Skip to content
Document DB v12 - Improved Interceptors with Soft Delete Integration, AI protections, & Admin UI with Aspire Integration!How!?

Peripheral

IPeripheral represents a BLE device discovered during scanning. It provides connection management and GATT operations.

Property Type Description
Uuid string Unique identifier for this peripheral
Name string? Local name (may be null)
Mtu int Current MTU size
Status ConnectionState Current connection state
IPeripheral peripheral; // from scan result
// Fire and forget - connects when in range
peripheral.Connect();
// Async - waits for connection to establish
await peripheral.ConnectAsync(cancelToken: cts.Token, timeout: TimeSpan.FromSeconds(10));

On Android, AutoConnect controls whether the system should automatically connect when the peripheral comes into range.

peripheral.Connect(new ConnectionConfig(AutoConnect: true));
peripheral.CancelConnection();
// or async
await peripheral.DisconnectAsync();

Always call CancelConnection() when you’re done with a peripheral. Not doing so will leave the connection open and drain the device battery.

peripheral
.WhenStatusChanged()
.Subscribe(state =>
{
// ConnectionState: Connecting, Connected, Disconnecting, Disconnected
});
// Convenience extensions
peripheral.WhenConnected().Subscribe(p => { /* connected */ });
peripheral.WhenDisconnected().Subscribe(p => { /* disconnected */ });
peripheral
.WhenConnectionFailed()
.Subscribe(ex =>
{
// BleException with details about the failure
});

MTU (Maximum Transmission Unit) determines the maximum data size per packet. The default is typically 20 bytes.

// Check if MTU requests are supported
if (peripheral.CanRequestMtu())
{
var newMtu = await peripheral.TryRequestMtuAsync(512);
Console.WriteLine($"Negotiated MTU: {newMtu}");
}
// Check if pairing is available
if (peripheral.IsPairingRequestsAvailable())
{
var result = await peripheral
.TryPairingRequest()
.ToTask();
if (result == true)
Console.WriteLine("Paired successfully");
}
// Check current pairing status
var status = peripheral.TryGetPairingStatus();
// PairingState: NotPaired, Paired
var rssi = await peripheral.ReadRssiAsync();
Console.WriteLine($"RSSI: {rssi} dBm");