Connecting to Multiple Devices

This section will show how to stream Respiration from two Aidlabs simultaneously:

1. Turn on your devices and wait for the LED to start pulsating. This indicates that the device is ready for connection.

2. Run the connectivity routine:

Python
Apple Platforms
import asyncio
from aidlab import AidlabManager, DataType, DeviceDelegate

FIRST_ADDRESS = "<YOUR FIRST DEVICE's ADDRESS>"
SECOND_ADDRESS = "<YOUR SECOND DEVICE's ADDRESS>"

class MainManager(DeviceDelegate):
    async def run(self):
        devices = await AidlabManager().scan()
        if len(devices) > 0:
            first_device = next((device for device in devices if device.address == FIRST_ADDRESS), None)
            second_device = next((device for device in devices if device.address == SECOND_ADDRESS), None)

            if first_device is not None:
                await first_device.connect(self)

            if second_device is not None:
                await second_device.connect(self)

            while True:
                await asyncio.sleep(1)

    async def did_connect(self, device):
        if device.address == FIRST_ADDRESS:
            await device.collect([DataType.RESPIRATION], [])
        elif device.address == SECOND_ADDRESS:
            await device.collect([DataType.RESPIRATION], [])

    def did_disconnect(self, device):
        print("Disconnected from:", device.address)

    def did_receive_respiration(self, device, _, values):
        if device.address == FIRST_ADDRESS:
            print("Respiration: ", values, device.address)
        elif device.address == SECOND_ADDRESS:
            print("Respiration: ", values, device.address)

asyncio.run(MainManager().run())
import Foundation
import Aidlab

let firstDeviceAddress = "<YOUR FIRST DEVICE's ADDRESS>"
let secondDeviceAddress = "<YOUR SECOND DEVICE's ADDRESS>"

class MainManager: AidlabManagerDelegate, DeviceDelegate {

    let aidlabManager: AidlabManager

    init() {
        aidlabManager = AidlabManager(delegate: self)
    }

    func run() {
        aidlabManager.scan()
    }

    func didDiscover(_ device: Device) {
        if device.address?.uuidString == firstDeviceAddress || device.address?.uuidString == secondDeviceAddress {
            device.connect(delegate: self, dataTypes: [.respiration], dataTypesToStore: [])
        }
    }

    func didDisconnect(_ device: Device) {
        print("Disconnected from: \(String(describing: device.address?.uuidString))")
    }

    func didReceiveRespiration(_ device: Device, timestamp _: UInt64, value: Float) {
        print("Did receive respiration: \(value), from \(String(describing: device.address))")
    }

    /// Rest of data handlers
    /// ...
}

func main() {
    let mainManager = MainManager()
    mainManager.run()

    /// ...
}

3. Wait till connection will be established.

Troubleshooting

Aidlab offers the ability to connect multiple devices simultaneously. However, it's important to note that the stability of these connections may vary depending on the Bluetooth chip version you're using. Particularly when connecting more than five devices, instability may occur.

During our internal tests conducted on a Raspberry Pi that was equipped with multiple Bluetooth dongles, we discovered that each individual dongle could maintain stable connections with up to 5 Aidlab devices. This means that the total number of Aidlab devices that can be concurrently connected is directly proportional to the number of Bluetooth dongles you have connected to your system. Specifically, the total count would be 5 times the number of dongles.

However, it's essential to understand that these outcomes might not be consistent for every setup. The actual number of stable connections you can achieve may vary depending on factors such as your specific hardware configuration and the version of your Bluetooth chipset.

In summary, Aidlab SDK does support connecting with multiple devices concurrently. But to ensure optimal performance, it's crucial to have a robust hardware setup that can handle these operations effectively.

results matching ""

    No results matching ""