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 Aidlab;
using System.Linq; // required for Select in the example belowCreate 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
Aidlab aidlab = new Aidlab(this);Scan 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() {
enableBluetooth();
setLocationPermission();
}
void onAidlabDetected(AndroidJavaObject device, int rssi) {
if (this.aidlab.isAidlabDetected()) return;
this.aidlab.onDeviceDetectedEvent();
Signal[] signals = { Signal.respirationRate, Signal.temperature };
device.Call("connect", signals.Select(x => (int) x).ToArray(), false, this.aidlab);
}
// Unity SDK currently targets Android; this example uses the Android bridge.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.