Skip to content

Peripheral

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

PropertyTypeDescription
UuidstringUnique identifier for this peripheral
Namestring?Local name (may be null)
MtuintCurrent MTU size
StatusConnectionStateCurrent 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");