Connecting to a Specified Device
Use the address reported by the SDK scan to reconnect to a known device. This is useful in labs and deployments where several supported devices are nearby.
Address formats depend on the platform:
- Android, Linux, and Windows normally expose a six-octet Bluetooth address such as
b9:b2:76:d7:ac:16. - Apple platforms expose a Core Bluetooth UUID such as
64cc003b-96f3-46f5-bc1e-d846e4555e79, not the hardware MAC address. Store the UUID discovered by the same app on the same Apple device; do not copy an address from Android or another computer. - Flutter follows the native platform: Android normally uses the six-octet address, while iOS uses the Core Bluetooth UUID.
The examples below assume that permissions and the manager/delegate setup from Establishing Connections are already in place.
The Flutter example also imports the underlying BLE client directly. Add it as an explicit dependency with flutter pub add flutter_reactive_ble.
python
async def connect_target(target_address: str, delegate: DeviceDelegate) -> Device:
devices = await AidlabManager().scan()
device = next(
(
item
for item in devices
if item.address.casefold() == target_address.casefold()
),
None,
)
if device is None:
raise RuntimeError(f"Device not found: {target_address}")
await device.connect(delegate)
return devicekotlin
// `aidlabManager` and the DeviceDelegate are created as in Establishing Connections.
val targetAddress = "B9:B2:76:D7:AC:16"
val device = aidlabManager.createDevice(targetAddress)
device.connect(this@MainActivity)swift
private let targetDeviceID = UUID(
uuidString: "64cc003b-96f3-46f5-bc1e-d846e4555e79"
)!
private var targetDevice: Device?
func didDiscover(_ device: Device) {
guard device.address == targetDeviceID else { return }
aidlabManager.stopScan()
targetDevice = device
device.connect(delegate: self)
}dart
import 'package:aidlab_sdk/aidlab_sdk.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart' as frb;
Future<Device> connectTarget(
String targetAddress,
DeviceDelegate delegate,
) async {
final ble = frb.FlutterReactiveBle();
final device = Device.withTransport(
transport: ReactiveBleAidlabTransport(
ble,
address: targetAddress,
name: null,
),
);
await device.connect(delegate);
return device;
}csharp
// The high-level Unity Desktop/iOS wrapper can filter only by device name.
Aidlab.AidlabSDK.init("Aidlab 2");
// Names are not guaranteed to be unique. Use the Android bridge or a lower-level
// platform SDK when deterministic address-based selection is required.