Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device was not found. #229

Closed
darkzbaron opened this issue Jun 26, 2020 · 3 comments
Closed

Device was not found. #229

darkzbaron opened this issue Jun 26, 2020 · 3 comments
Assignees
Labels
Backend: pythonnet Issues or PRs relating to the .NET/pythonnet backend Documentation Issues or PRs relating to RTD or documentation
Milestone

Comments

@darkzbaron
Copy link

darkzbaron commented Jun 26, 2020

  • bleak version:0.6.4
  • Python version: Python 3.6.0rc2 (v3.6.0rc2:800a67f7806d, Dec 16 2016, 23:22:07) [MSC v.1900 64 bit (AMD64)] on win32
  • Operating System: Windows 10

Description

I am trying to catch a "Device with address [ADDRESSMAC] was not found." and perform an action when this occurs. Ideally a retry or something like this.

What I Did

I am using the example code but I can't find where the error would be stored and how to catch it with an async method

Any help would be more than welcome.

# -*- coding: utf-8 -*-
"""
Notifications
-------------

Example showing how to add notifications to a characteristic and handle the responses.

Updated on 2019-07-03 by hbldh 

"""

import logging
import asyncio
import platform

from bleak import BleakClient
from bleak import _logger as logger


CHARACTERISTIC_UUID = (
    "f000aa65-0451-4000-b000-000000000000"
)  # <--- Change to the characteristic you want to enable notifications from.


def notification_handler(sender, data):
    """Simple notification handler which prints the data received."""
    print("{0}: {1}".format(sender, data))


async def run(address, loop, debug=False):
    if debug:
        import sys

        # loop.set_debug(True)
        l = logging.getLogger("asyncio")
        l.setLevel(logging.DEBUG)
        h = logging.StreamHandler(sys.stdout)
        h.setLevel(logging.DEBUG)
        l.addHandler(h)
        logger.addHandler(h)

    async with BleakClient(address, loop=loop) as client:
        x = await client.is_connected()
        logger.info("Connected: {0}".format(x))

        await client.start_notify(CHARACTERISTIC_UUID, notification_handler)
        await asyncio.sleep(5.0, loop=loop)
        await client.stop_notify(CHARACTERISTIC_UUID)


if __name__ == "__main__":
    import os

    os.environ["PYTHONASYNCIODEBUG"] = str(1)
    address = (
        "24:71:89:cc:09:05"  # <--- Change to your device's address here if you are using Windows or Linux
        if platform.system() != "Darwin"
        else "243E23AE-4A99-406C-B317-18F1BD7B4CBE"  # <--- Change to your device's address here if you are using macOS
    )
    loop = asyncio.get_event_loop()

    while connect_retries < connect_retries_max:
     try:
      connection = loop.run_until_complete(run(address, loop, True))
      break
     except:
      connect_retries += 1
@hbldh hbldh self-assigned this Jun 30, 2020
@hbldh hbldh added Backend: pythonnet Issues or PRs relating to the .NET/pythonnet backend Documentation Issues or PRs relating to RTD or documentation labels Jun 30, 2020
@hbldh
Copy link
Owner

hbldh commented Jun 30, 2020

I will try to make a new example file for this shortly.

@darkzbaron
Copy link
Author

Hi, thanks so much for the work. I think the disconnect example doesn't work with my system too! Thanks for making the only working Python Bluetooth LE Api on Windows!

@hbldh hbldh added this to the Version 0.7.X milestone Jun 30, 2020
@hbldh hbldh modified the milestones: Version 0.7.X, Version 0.8.0 Jul 9, 2020
@hbldh hbldh modified the milestones: Version 0.8.0, Version 0.X.Y Aug 18, 2020
@dlech
Copy link
Collaborator

dlech commented Oct 6, 2021

This sounds like a use case for #527, so will close in favor of that issue.

@dlech dlech closed this as completed Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: pythonnet Issues or PRs relating to the .NET/pythonnet backend Documentation Issues or PRs relating to RTD or documentation
Projects
None yet
Development

No branches or pull requests

3 participants