Kotlin Multiplatform BLE library for iOS, Android, macos, windows and javascript
Blue-FalconA Bluetooth Low Energy (BLE) Kotlin Multiplatform library for iOS, Android, MacOS, Raspberry Pi, Windows, and JavaScript.
Blue Falcon provides a unified API for Bluetooth LE operations across all platforms. Each platform implementation compiles to native code, ensuring optimal performance and seamless integration with platform-specific APIs.
🎉 Version 3.0 introduces a plugin-based engine architecture inspired by Ktor, enabling extensibility while maintaining 100% backward compatibility with 2.x.
Simply update your version - no code changes required:
commonMain.dependencies {
implementation("dev.bluefalcon:blue-falcon:3.0.0")
}
Your existing 2.x code continues to work unchanged! See the Migration Guide for details.
commonMain.dependencies {
implementation("dev.bluefalcon:blue-falcon-core:3.0.0")
}
// Add platform-specific engines
androidMain.dependencies {
implementation("dev.bluefalcon:blue-falcon-engine-android:3.0.0")
}
iosMain.dependencies {
implementation("dev.bluefalcon:blue-falcon-engine-ios:3.0.0")
}
commonMain.dependencies {
// Logging support
implementation("dev.bluefalcon:blue-falcon-plugin-logging:3.0.0")
// Automatic retry with exponential backoff
implementation("dev.bluefalcon:blue-falcon-plugin-retry:3.0.0")
// Service/characteristic caching
implementation("dev.bluefalcon:blue-falcon-plugin-caching:3.0.0")
}
// Create instance
val blueFalcon = BlueFalcon(log = null, ApplicationContext())
// Register delegate
blueFalcon.delegates.add(object : BlueFalconDelegate {
override fun didDiscoverDevice(peripheral: BluetoothPeripheral, advertisementData: Map<AdvertisementDataRetrievalKeys, Any>) {
println("Found device: ${peripheral.name}")
}
override fun didConnect(peripheral: BluetoothPeripheral) {
println("Connected to: ${peripheral.name}")
}
})
// Start scanning
blueFalcon.scan()
import dev.bluefalcon.core.*
import dev.bluefalcon.plugins.logging.*
// Configure with DSL
val blueFalcon = BlueFalcon {
engine = AndroidEngine(context) // or iOSEngine(), macOSEngine(), etc.
install(LoggingPlugin) {
level = LogLevel.DEBUG
}
install(RetryPlugin) {
maxAttempts = 3
initialDelay = 500
}
}
// Reactive Flow API
launch {
blueFalcon.peripherals.collect { devices ->
devices.forEach { device ->
println("Device: ${device.name}")
}
}
}
// Start scanning
blueFalcon.scan()
| Platform | Engine Module | Status | Notes |
|---|---|---|---|
| Android | blue-falcon-engine-android |
✅ Stable | Full BLE support including L2CAP, bonding |
| iOS | blue-falcon-engine-ios |
✅ Stable | CoreBluetooth wrapper |
| macOS | blue-falcon-engine-macos |
✅ Stable | CoreBluetooth wrapper |
| JavaScript | blue-falcon-engine-js |
✅ Stable | Web Bluetooth API |
| Windows | blue-falcon-engine-windows |
✅ Stable | WinRT via JNI (Windows 10 1803+) |
| Raspberry Pi | blue-falcon-engine-rpi |
✅ Stable | Blessed library (BlueZ) |
Blue Falcon 3.0 uses a three-layer architecture:
┌─────────────────────────────────────────┐
│ Your Application Code │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Core (Interfaces + Plugin System) │
│ • BlueFalcon API │
│ • Plugin Registry │
│ • Type Definitions │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Platform Engines (6 implementations) │
│ • AndroidEngine │
│ • iOSEngine, macOSEngine │
│ • JSEngine │
│ • WindowsEngine │
│ • RPiEngine │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ Native Platform APIs │
│ • Android Bluetooth │
│ • CoreBluetooth (iOS/macOS) │
│ • Web Bluetooth │
│ • Windows WinRT │
│ • BlueZ (Linux) │
└─────────────────────────────────────────┘
See the Plugin Development Guide to create your own!
We welcome contributions! Blue Falcon follows a structured decision-making process:
For significant architectural changes or new features:
# Use the ADR template
cp docs/adr/ADR-TEMPLATE.md docs/adr/XXXX-your-proposal.md
For bug fixes, docs, or small improvements:
See CONTRIBUTING.md for detailed guidelines.
blueFalcon.clearPeripherals()
// Check scanning state val scanning: Boolean = blueFalcon.isScanning
#### Observing Discovered Devices
```kotlin
// Observe discovered peripherals via StateFlow
blueFalcon.peripherals.collect { peripherals: Set<BluetoothPeripheral> ->
// update your UI with the discovered devices
}
// Observe Bluetooth manager state (Ready / NotReady)
blueFalcon.managerState.collect { state: BluetoothManagerState ->
when (state) {
BluetoothManagerState.Ready -> { /* Bluetooth is available */ }
BluetoothManagerState.NotReady -> { /* Bluetooth is unavailable */ }
}
}
// Connect to a peripheral (autoConnect = false for direct connection)
blueFalcon.connect(bluetoothPeripheral, autoConnect = false)
// Disconnect from a peripheral
blueFalcon.disconnect(bluetoothPeripheral)
// Check current connection state
val state: BluetoothPeripheralState = blueFalcon.connectionState(bluetoothPeripheral)
// Returns: Connecting, Connected, Disconnected, Disconnecting, or Unknown
// Request connection priority (Android-specific, no-op on other platforms)
blueFalcon.requestConnectionPriority(bluetoothPeripheral, ConnectionPriority.High)
// Options: ConnectionPriority.Balanced, ConnectionPriority.High, ConnectionPriority.Low
// Retrieve a previously known peripheral by identifier
val peripheral: BluetoothPeripheral? = blueFalcon.retrievePeripheral("device-identifier")
// Android: MAC address format (e.g., "00:11:22:33:44:55")
// iOS/Native: UUID format (e.g., "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
When autoDiscoverAllServicesAndCharacteristics is true (default), services and characteristics are discovered automatically after connection. You can also trigger discovery manually:
// Discover services (optionally filter by service UUIDs)
blueFalcon.discoverServices(bluetoothPeripheral, serviceUUIDs = emptyList())
// Discover characteristics for a specific service (optionally filter by UUIDs)
blueFalcon.discoverCharacteristics(
bluetoothPeripheral,
bluetoothService,
characteristicUUIDs = emptyList()
)
// Read a characteristic value
blueFalcon.readCharacteristic(bluetoothPeripheral, bluetoothCharacteristic)
// Write a string value
blueFalcon.writeCharacteristic(
bluetoothPeripheral,
For the complete API including descriptors, MTU, L2CAP, and bonding, see the API Reference.
Blue Falcon is released under the MIT License.
Made with ❤️ by the Blue Falcon community