Giter Club home page Giter Club logo

Comments (4)

hbldh avatar hbldh commented on August 23, 2024

Can you try to connect to two devices in macOS using two different terminals and see if that works. If so, then there is a limitation in the bleak macOS backend that needs to be documented.

See this for similar problem: https://stackoverflow.com/questions/34787976/how-can-i-implement-core-bluetooth-functionality-for-multiple-devices

from bleak.

Szymon-Gesicki avatar Szymon-Gesicki commented on August 23, 2024

It took me a while 😀 I did what you said. Bleak connects correctly to two devices at two different terminals. Unfortunately with one terminal, just like in my example, it stops before
async with BleakClient(address, loop=loop) as client:.
On Windows everything works perfect.

from bleak.

hbldh avatar hbldh commented on August 23, 2024

Ok. I will add a note about this in the documentation for the time being. This issue is beyond the scope of my available time to address.

from bleak.

hbldh avatar hbldh commented on August 23, 2024

This is solved in the last develop branch commit and will be available on PyPI in version 0.7.0.

The following code should now work:

from bleak import BleakClient
import asyncio

notify_uuid = "0000{0:x}-0000-1000-8000-00805f9b34fb".format(0xffe1)


def callback(sender, data):
    print(sender, data)


def run(addresses):
    loop = asyncio.get_event_loop()

    tasks = asyncio.gather(
        *(connect_to_device(address, loop) for address in addresses)
    )

    loop.run_until_complete(tasks)


async def connect_to_device(address, loop):
    print("starting", address, "loop")
    async with BleakClient(address, loop=loop, timeout=10.0) as client:

        print("connect to", address)
        try:
            await client.start_notify(notify_uuid, callback)
            await asyncio.sleep(10.0, loop=loop)
            await client.stop_notify(notify_uuid)
        except Exception as e:
            print(e)

    print("disconnect from", address)

if __name__ == "__main__":
    run(["B9EA5233-37EF-4DD6-87A8-2A875E821C46", "F0CBEBD3-299B-4139-A9FC-44618C720157" ])

from bleak.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.