Quickstart
Run a Bluetooth Low Energy scan with SimpleBLE in C++, C, Python, Java, Rust, Node.js, React Native, Kotlin, Swift, Delphi, Unity or Unreal to check your setup.
This quickstart gets you to the first adoption milestone: your application can see nearby BLE devices. After that, move to the Connect and Read, Write, Notify recipes, or Advertise to host a local peripheral.
Before you run
- Install the binding or enable the plugin for your target environment.
- Turn on Bluetooth on the host device.
- Grant OS permissions when required. On macOS, iOS, and Android this usually means app-level permission prompts or manifest entries.
- Keep at least one BLE peripheral nearby and advertising.
Scan for nearby devices
#include <cstdlib>
#include <iostream>
#include <simpleble/SimpleBLE.h>
int main() {
if (!SimpleBLE::Adapter::bluetooth_enabled()) {
std::cerr << "Bluetooth is not enabled or permission is missing." << std::endl;
return EXIT_FAILURE;
}
auto adapters = SimpleBLE::Adapter::get_adapters();
if (adapters.empty()) {
std::cerr << "No Bluetooth adapters found." << std::endl;
return EXIT_FAILURE;
}
auto adapter = adapters.front();
std::cout << "Using adapter: " << adapter.identifier() << " [" << adapter.address() << "]" << std::endl;
adapter.set_callback_on_scan_found([](SimpleBLE::Peripheral peripheral) {
std::cout << "Found: " << peripheral.identifier()
<< " [" << peripheral.address() << "] "
<< peripheral.rssi() << " dBm" << std::endl;
});
adapter.scan_for(5000);
std::cout << "Scan results:" << std::endl;
for (auto& peripheral : adapter.scan_get_results()) {
std::cout << "- " << peripheral.identifier()
<< " [" << peripheral.address() << "] "
<< (peripheral.is_connectable() ? "connectable" : "not connectable")
<< std::endl;
}
return EXIT_SUCCESS;
}#include <stdio.h>
#include <stdlib.h>
#include <simplecble/simplecble.h>
int main(void) {
simpleble_error_t* error = NULL;
simpleble_adapter_list_t adapters = NULL;
simpleble_adapter_get_adapters(&adapters, &error);
simpleble_adapter_t adapter = error ? NULL : simpleble_adapter_list_get(adapters, 0, &error);
simpleble_adapter_list_release(adapters);
if (error) {
fprintf(stderr, "%s\n", simpleble_error_message(error));
simpleble_error_release(&error);
return EXIT_FAILURE;
}
simpleble_peripheral_list_t results = NULL;
simpleble_adapter_scan_for(adapter, 5000, &error);
if (!error) {
size_t count = simpleble_adapter_scan_get_results(adapter, &results, &error);
for (size_t i = 0; i < count && !error; i++) {
simpleble_peripheral_t peripheral = simpleble_peripheral_list_get(results, i, &error);
if (error) break;
char* identifier = simpleble_peripheral_identifier(peripheral, &error);
if (!error) printf("Found: %s\n", identifier);
simpleble_free(identifier);
simpleble_peripheral_release_handle(peripheral);
}
}
int result = error ? EXIT_FAILURE : EXIT_SUCCESS;
if (error) fprintf(stderr, "%s\n", simpleble_error_message(error));
simpleble_error_release(&error);
simpleble_peripheral_list_release(results);
simpleble_adapter_release_handle(adapter);
return result;
}import simplepyble
adapters = simplepyble.Adapter.get_adapters()
if not adapters:
raise SystemExit("No Bluetooth adapters found.")
adapter = adapters[0]
print(f"Using adapter: {adapter.identifier()} [{adapter.address()}]")
adapter.set_callback_on_scan_found(
lambda peripheral: print(
f"Found: {peripheral.identifier()} [{peripheral.address()}] {peripheral.rssi()} dBm"
)
)
adapter.scan_for(5000)
print("Scan results:")
for peripheral in adapter.scan_get_results():
state = "connectable" if peripheral.is_connectable() else "not connectable"
print(f"- {peripheral.identifier()} [{peripheral.address()}] {state}")import org.simplejavable.Adapter;
import org.simplejavable.Peripheral;
import java.util.List;
public class ScanExample {
public static void main(String[] args) throws Exception {
if (!Adapter.isBluetoothEnabled()) {
System.err.println("Bluetooth is not enabled or permission is missing.");
return;
}
List<Adapter> adapters = Adapter.getAdapters();
if (adapters.isEmpty()) {
System.err.println("No Bluetooth adapters found.");
return;
}
Adapter adapter = adapters.get(0);
System.out.println("Using adapter: " + adapter.getIdentifier() + " [" + adapter.getAddress() + "]");
adapter.setEventListener(new Adapter.EventListener() {
@Override
public void onScanFound(Peripheral peripheral) {
System.out.println("Found: " + peripheral.getIdentifier()
+ " [" + peripheral.getAddress() + "] "
+ peripheral.getRssi() + " dBm");
}
});
adapter.scanFor(5000);
System.out.println("Scan results:");
for (Peripheral peripheral : adapter.scanGetResults()) {
String state = peripheral.isConnectable() ? "connectable" : "not connectable";
System.out.println("- " + peripheral.getIdentifier()
+ " [" + peripheral.getAddress() + "] "
+ state);
}
}
}Add the dependency:
[dependencies]
simplersble = "1"
tokio = { version = "1", features = ["full"] }
futures = "0.3"Then scan:
use std::time::Duration;
use futures::stream::StreamExt;
#[tokio::main]
async fn main() {
let mut adapters = simplersble::Adapter::get_adapters().unwrap();
if adapters.is_empty() {
println!("No Bluetooth adapters found.");
return;
}
let adapter = adapters.remove(0);
let mut events = adapter.on_scan_event();
tokio::spawn(async move {
while let Some(event) = events.next().await {
if let simplersble::ScanEvent::Found(peripheral) = event {
println!(
"Found: {} [{}] {} dBm",
peripheral.identifier().unwrap(),
peripheral.address().unwrap(),
peripheral.rssi().unwrap()
);
}
}
});
adapter.scan_for(Duration::from_secs(5)).unwrap();
println!("Scan results:");
for peripheral in adapter.scan_get_results().unwrap() {
println!(
"- {} [{}]",
peripheral.identifier().unwrap(),
peripheral.address().unwrap()
);
}
}Install the package:
npm install simplejsbleThen save this as scan.mjs and run node scan.mjs:
import { Adapter } from 'simplejsble';
const [adapter] = await Adapter.getAdapters();
console.log(`Using adapter: ${adapter.identifier()} [${adapter.address()}]`);
adapter.on('scanFound', peripheral => {
console.log(`Found: ${peripheral.identifier()} [${peripheral.address()}] ${peripheral.rssi()} dBm`);
});
await adapter.scanFor(5000);
console.log('Scan results:');
for (const peripheral of adapter.scanGetResults()) {
const state = peripheral.isConnectable() ? 'connectable' : 'not connectable';
console.log(`- ${peripheral.identifier()} [${peripheral.address()}] ${state}`);
}Install the package and Nitro Modules:
npm install simplernble react-native-nitro-modules
cd ios && pod installAdd the Bluetooth permissions from SimpleRnBLE Usage, then use this as App.tsx:
import { useState } from 'react';
import { Button, FlatList, PermissionsAndroid, Platform, Text, View } from 'react-native';
import { Adapter, type Peripheral } from 'simplernble';
export default function App() {
const [peripherals, setPeripherals] = useState<Peripheral[]>([]);
const scan = async () => {
if (Platform.OS === 'android') {
await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
]);
}
const [adapter] = await Adapter.getAdapters();
const update = () => setPeripherals(adapter.scanGetResults());
adapter.on('scanFound', update);
try {
await adapter.scanFor(5000);
} finally {
adapter.off('scanFound', update);
}
};
return (
<View style={{ flex: 1, paddingTop: 64, paddingHorizontal: 16 }}>
<Button title="Scan for 5 seconds" onPress={scan} />
<FlatList
data={peripherals}
keyExtractor={peripheral => peripheral.address()}
renderItem={({ item }) => (
<Text>
{item.identifier()} [{item.address()}] {item.rssi()} dBm
</Text>
)}
/>
</View>
);
}Add the dependency to your shared module:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("org.simpleble:simplektble:<version>")
}
}
}Then scan from shared code:
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.simplektble.Adapter
suspend fun scan() = coroutineScope {
val adapter = Adapter.getAdapters().first()
println("Using adapter: ${adapter.identifier} [${adapter.address}]")
val found = launch(start = CoroutineStart.UNDISPATCHED) {
adapter.onScanFound.collect { peripheral ->
println("Found: ${peripheral.identifier} [${peripheral.address}] ${peripheral.rssi} dBm")
}
}
adapter.scanFor(5000)
found.cancel()
println("Scan results:")
for (peripheral in adapter.scanGetResults()) {
val state = if (peripheral.isConnectable) "connectable" else "not connectable"
println("- ${peripheral.identifier} [${peripheral.address}] $state")
}
}Call scan() from a coroutine, such as lifecycleScope.launch { scan() } on Android or suspend fun main() = scan() on the JVM. On Android, request the Bluetooth permissions first with SimpleKtBle.requestPermissions(activity). On iOS and macOS, add NSBluetoothAlwaysUsageDescription to your app's Info.plist. See SimpleKtBLE Usage for details.
Add the package in Xcode with File > Add Package Dependencies, or in your Package.swift:
dependencies: [
.package(url: "https://github.com/simpleble/simpleswiftble", from: "<version>")
],
targets: [
.target(name: "MyApp", dependencies: [.product(name: "SimpleSwiftBLE", package: "simpleswiftble")])
]Then scan:
import SimpleSwiftBLE
let adapter = try Adapter.getAdapters().first!
print("Using adapter: \(adapter.identifier) [\(adapter.address)]")
let found = adapter.onScanFound
let printer = Task {
for await peripheral in found {
print("Found: \(peripheral.identifier) [\(peripheral.address)] \(peripheral.rssi) dBm")
}
}
try await adapter.scanFor(timeoutMs: 5000)
printer.cancel()
print("Scan results:")
for peripheral in try adapter.scanGetResults() {
let state = peripheral.isConnectable ? "connectable" : "not connectable"
print("- \(peripheral.identifier) [\(peripheral.address)] \(state)")
}Run it from asynchronous code, such as a SwiftUI .task modifier or the main.swift of a command-line tool. Add NSBluetoothAlwaysUsageDescription to your app's Info.plist. See SimpleSwiftBLE Usage for details.
Create a Dart program and add the package:
dart create scan
cd scan
dart pub add simpledartbleThen replace bin/scan.dart with this and run dart run:
import 'package:simpledartble/simpledartble.dart';
Future<void> main() async {
final adapter = (await Adapter.getAdapters()).first;
print('Using adapter: ${adapter.identifier} [${adapter.address}]');
adapter.onScanFound.listen((peripheral) {
print('Found: ${peripheral.identifier} [${peripheral.address}] ${peripheral.rssi} dBm');
});
await adapter.scanFor(const Duration(seconds: 5));
print('Scan results:');
for (final peripheral in adapter.scanGetResults()) {
final state = peripheral.isConnectable ? 'connectable' : 'not connectable';
print('- ${peripheral.identifier} [${peripheral.address}] $state');
}
}In a Flutter app, use SimpleFltBLE: run flutter pub add simplefltble, import package:simplefltble/simplefltble.dart, and call the same code from your app. On Android, request the Bluetooth permissions first, and on iOS and macOS, add NSBluetoothAlwaysUsageDescription to your app's Info.plist. See SimpleFltBLE Usage for details.
Install SimpleDelphiBLE with Boss, or add the source folder of a release to your search path:
boss install github.com/simpleble/simpledelphibleThen scan from a console program:
program scan;
{$IFDEF FPC}
{$MODE DELPHIUNICODE}
{$ENDIF}
{$IFDEF MSWINDOWS}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
SimpleDelphiBLE;
type
TScanPrinter = class
procedure ScanFound(Sender: TBleAdapter; Peripheral: TBlePeripheral);
end;
procedure TScanPrinter.ScanFound(Sender: TBleAdapter; Peripheral: TBlePeripheral);
begin
WriteLn('Found: ', Peripheral.Identifier, ' [', Peripheral.Address, '] ', Peripheral.Rssi, ' dBm');
end;
var
Adapters: TArray<TBleAdapter>;
Adapter: TBleAdapter;
Peripheral: TBlePeripheral;
Printer: TScanPrinter;
begin
if not TBleAdapter.IsBluetoothEnabled then
raise Exception.Create('Bluetooth is not enabled or permission is missing.');
Adapters := TBleAdapter.GetAdapters;
if Length(Adapters) = 0 then
raise Exception.Create('No Bluetooth adapters found.');
Adapter := Adapters[0];
WriteLn('Using adapter: ', Adapter.Identifier, ' [', Adapter.Address, ']');
Printer := TScanPrinter.Create;
Adapter.OnScanFound := Printer.ScanFound;
Adapter.ScanFor(5000);
WriteLn('Scan results:');
for Peripheral in Adapter.ScanGetResults do
if Peripheral.IsConnectable then
WriteLn('- ', Peripheral.Identifier, ' [', Peripheral.Address, '] connectable')
else
WriteLn('- ', Peripheral.Identifier, ' [', Peripheral.Address, '] not connectable');
end.Keep the native SimpleBLE library for your platform next to the program, and on macOS add NSBluetoothAlwaysUsageDescription to your app's Info.plist. In VCL, FMX, and Lazarus applications, OnScanFound runs on the main thread. See SimpleDelphiBLE Usage for deployment and Free Pascal settings.
Declare Bluetooth permissions and request them at runtime before calling the adapter APIs. A minimal Compose scan flow looks like this:
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import kotlinx.coroutines.launch
import org.simpleble.android.Adapter
@Composable
fun ScanScreen() {
val adapter = remember { Adapter.getAdapters().first() }
val results = remember { mutableStateOf(emptyList<String>()) }
LaunchedEffect(Unit) {
launch {
adapter.onScanFound.collect { peripheral ->
val line = "${peripheral.identifier} [${peripheral.address}] ${peripheral.rssi} dBm"
Log.d("SimpleBLE", line)
results.value = results.value + line
}
}
adapter.scanFor(5000)
}
}The full Android example app shows permission setup, adapter ownership, scanning, connection, GATT read/write, notification, and cleanup flows.
Use the Unreal plugin nodes to run a short scan from Blueprint:
- Create a
Simple BLE Managerobject and keep it referenced while the scan is active. - Bind
On Device Foundto collect or display discovered device names. - Bind
On Scan Finishedto update your UI when discovery ends. - Call
Initialize. - If initialization succeeds, call
Start Scanwith a timeout such as5000. - Use
Get Found Devicesto inspect the discovered device names, identifiers, or addresses.
For C++ Unreal projects, create and keep a USimpleBLEManager reference on a UObject that outlives the scan:
#include "SimpleBLE/Manager.h"
void UMyBluetoothController::StartBluetoothScan()
{
Manager = NewObject<USimpleBLEManager>(this);
Manager->OnDeviceFound.AddDynamic(this, &UMyBluetoothController::HandleDeviceFound);
Manager->OnScanFinished.AddDynamic(this, &UMyBluetoothController::HandleScanFinished);
if (!Manager->Initialize())
{
UE_LOG(LogTemp, Warning, TEXT("SimpleBLE could not initialize."));
return;
}
Manager->StartScan(5000);
}See the SimpleBLE for Unreal quickstart for connect, read, write, notify, payload helpers, and the lower-level adapter/peripheral API.
Use the SimpleBLE for Unity scan component on a GameObject and enter Play mode. It initializes Bluetooth, scans for five seconds and prints nearby devices to the Console. On Android, accept the Nearby devices permission prompt.
What this proves
If the scan prints devices or the Unreal scan callback reports devices, the binding or plugin is wired up, the OS backend is available, Bluetooth is enabled, and permissions are good enough for discovery. The next step is to connect to one of the connectable peripherals and inspect its GATT services.
Next steps
- Scan recipe: scan lifecycle, callbacks, and result handling.
- Connect recipe: choose a device, connect, list services and characteristics.
- Read, Write, Notify: perform GATT operations once connected.
- SimpleBLE for Unreal quickstart: Blueprint and C++ flows for Unreal Engine projects.
Installation
Install SimpleBLE for C++, C, C#, Python, Java, Kotlin, Swift, Go, Rust, Delphi, Node.js, React Native, Unity or Unreal, with each platform's prerequisites.
Dongl Adapter
Dongl is a USB Bluetooth adapter made for SimpleBLE. Use one or several as extra adapters, pair and bond with devices, and update the Dongl firmware.
