Michael Pekelis
Michael Pekelis

Reputation: 1

Bluetooth connectivity issues when connecting multiple Muse IMU devices with Python/Bleak

I'm currently am using python with bleak and I'm finding it difficult to connect and maintain a stable connection to multiple Bluetooth enabled imu devices (muse), especially when trying to connect multiple devices at the same time Any tips and advice on how to best manage the Bluetooth connections and ensure stability across multiple devices? Maybe someone knows a good alternative to bleak?

I'm also thinking about switching to the Bluetooth web api, to be able to connect directly from the browser as it minimizes the amount of "moving parts" in my project as there is also a front-end web based ui that eventually interacts with the python server via a web socket, is it a good idea to switch to it?

When implementing multi-device Bluetooth connectivity, I tried three different approaches


async def connect_devices(device_names):
    for name in device_names:
        manager = BleManager(name, logger)
        success, msg = await manager.connect()
        if not success:
            logger.error(f"Failed to connect to {name}: {msg}")

-I expected each device to maintain a stable connection while connecting to additional devices. But when actually connecting, the previously connected device would often become unstable or disconnect entirely

async def connect_parallel(device_names):
    managers = [BleManager(name, logger) for name in device_names]
    tasks = [manager.connect() for manager in managers]
    results = await asyncio.gather(*tasks, return_exceptions=True)

-I also tried to establish connections by connecting to all devices simultaneously it resulted in devices frequently failing to connect at all or disconnecting shortly after connection

async def connect_with_retry(device_name, max_attempts=3):
    for attempt in range(max_attempts):
        manager = BleManager(device_name, logger)
        success, msg = await manager.connect()
        if success:
            return manager
        await asyncio.sleep(1) 

-Devices would still disconnect unpredictably when multiple devices were connected

The Bluetooth connectivity aspect overall works, I eventually am able to connect to all devices simultaneously, and am able to stream data from them, but its unreliable, it usually takes multiple attempts, this is my main problem

Upvotes: 0

Views: 19

Answers (0)

Related Questions