Examples
Runnable SimpleKtBLE examples for the JVM that list adapters, scan, connect, read, write, receive notifications, host a GATT service and use a Dongl.
The examples live alongside the other SimpleBLE binding examples:
- ListAdapters: Check whether Bluetooth is enabled and print each adapter.
- ListBackends: Enumerate backends and list the adapters provided by each one.
- Scan: Scan for five seconds, printing peripherals with their signal strength as they are found and updated, then whether each is connectable and its manufacturer data.
- Connect: Connect to a peripheral and list its services, characteristics with their capabilities, and descriptors.
- Read: Connect to a peripheral and print a GATT characteristic in hex.
- Write: Connect to a peripheral and write text to a GATT characteristic.
- Notify: Connect to a peripheral and print the notifications of a characteristic for five seconds.
- Peripheral: Host a GATT service that echoes writes to subscribed clients and prints client and subscription events.
- Dongl: Scan with a Dongl adapter, then connect and answer pairing requests.
The examples are a Gradle project for the jvm target that builds SimpleKtBLE
from the checkout. Run one from the repository root with its task:
utils/gradle/gradlew -p examples/simplektble runScanEach example has a task named after it, from runListAdapters to runDongl.
The examples ask for their choices on the console, and runPeripheral runs
until you press Ctrl+C.
For binding development, see the development guide. For events, lifetime, and handlers, see Usage.
Usage
Install SimpleKtBLE, the Kotlin Multiplatform binding for SimpleBLE, and use it on Android, iOS, macOS, Windows and Linux to scan, connect and host services.
Usage
Install SimpleSwiftBLE with Swift Package Manager and use SimpleBLE from Swift on iOS, iPadOS, macOS and Mac Catalyst with async/await calls and SwiftUI.
