Establishing Connections
Aidlab SDK lets you discover and connect to nearby devices. Typical workflow: import the SDK, initialize the manager and delegate, scan for available devices, then establish a connection and start collecting data. Make sure the device is worn correctly (pulsating green LED) before scanning.
Imports
python
from aidlab import AidlabManager, DeviceDelegate, DataTypekotlin
import com.aidlab.sdk.*swift
import Aidlabdart
import 'package:aidlab_sdk/aidlab_sdk.dart';csharp
using UnityEngine;
using Aidlab;Create the manager
python
class MainManager(DeviceDelegate):
def did_connect(self, device):
print("Connected to:", device.address)
# add handlers / collect in the scan step belowkotlin
class MainActivity : ComponentActivity(), DeviceDelegate, AidlabManagerDelegate {
private lateinit var aidlabManager: AidlabManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
aidlabManager = AidlabManager(this, this)
}
}swift
let aidlabManager = AidlabManager(delegate: self)dart
late AidlabManager aidlabManager;
aidlabManager = AidlabManager(this);csharp
// Desktop (Windows/macOS) + iOS:
Aidlab.AidlabSDK.init(); // starts scanning/connecting automatically
Aidlab.AidlabSDK.init("Aidlab 2"); // optional device name filter
// Android:
// Implement `AidlabDelegate` and create the Android bridge:
// var aidlab = new Aidlab(this); // starts scanning automaticallyScan and connect
Ensure the device is worn correctly (pulsating green LED) before scanning.
python
import asyncio
class MainManager(DeviceDelegate):
async def run(self):
devices = await AidlabManager().scan()
if devices:
print("Connecting to:", devices[0].address)
await devices[0].connect(self)
while True:
await asyncio.sleep(1)
asyncio.run(MainManager().run())kotlin
fun onBluetoothRequestsGranted() {
aidlabManager.scan()
}
override fun didDiscover(device: Device, rssi: Int) {
device.connect(this)
}
// Ensure Bluetooth/location permissions are granted before calling scan()swift
aidlabManager.scan()
func didDiscover(_ device: Device) {
device.connect(delegate: self)
}dart
@override
void didDiscover(Device device, int rssi) {
device.connect(this);
}csharp
void Start() {
// Desktop (Windows/macOS) + iOS:
Aidlab.AidlabSDK.init("Aidlab"); // default matches "Aidlab 2" as well
// Android:
// Request runtime Bluetooth permissions (Android 12+) before scanning/connecting,
// then create the bridge:
// aidlab = new Aidlab(this);
}Bluetooth scanning relies on radio signals, so immediate discovery is not guaranteed; retry if needed. To connect to a specific device, see Connecting to a Specified Device.