Giter Site home page Giter Site logo

Comments (4)

mactabish avatar mactabish commented on June 13, 2024

@bedenko any idea for a quick solution to this?

from adafruit_python_bluefruitle.

bedenko avatar bedenko commented on June 13, 2024

Well, at least for linux part, this part is hard-coded, so "Adapter1" and "Device1" are static.

Quick fix: change the value Adapter1 to Adapter2
Permanent fix: change the code, to be able to switch between adapters.

P.S.: this line also returns following error:

AttributeError: 'NoneType' object has no attribute 'GetManagedObjects'

from adafruit_python_bluefruitle.

neomanic avatar neomanic commented on June 13, 2024

You can use adapters = ble.list_adapters(), then choose the adapter you want from the list using indexing adapter = adapters[-1].

But on a related issue, I wasn't sure that the adapters would always be enumerated in the right order, so I added adapter selection using the MAC of the Bluetooth dongle, as follows.

Add the following patch to the library, which gives you easy access to the BLE adapter address:

diff --git a/Adafruit_BluefruitLE/bluez_dbus/adapter.py b/Adafruit_BluefruitLE/bluez_dbus/adapter.py
index 0d262d2..811c0bc 100644
--- a/Adafruit_BluefruitLE/bluez_dbus/adapter.py
+++ b/Adafruit_BluefruitLE/bluez_dbus/adapter.py
@@ -62,7 +62,13 @@ class BluezAdapter(Adapter):
     def name(self):
         """Return the name of this BLE network adapter."""
         return self._props.Get(_INTERFACE, 'Name')
-
+        
+    @property
+    def address(self):
+        """Return the address of this BLE network adapter."""
+        return self._props.Get(_INTERFACE, 'Address')
+        
+        
     def start_scan(self, timeout_sec=TIMEOUT_SEC):
         """Start scanning for BLE devices with this adapter."""
         self._scan_started.clear()

Then in my initialisation code, I have:

    adapters = ble.list_adapters()
    adapter = None
    if len(adapters) == 1:
        print("Single Bluetooth adapter found (no MAC filtering).")
        adapter = adapters[0]
    if len(adapters) > 1:
        filtered_adapters = [a for a in adapters if a.address == BLUETOOTH_ADAPTER_MAC]
        if len(filtered_adapters) > 0:
            print("Multiple Bluetooth adapters found: filtered by MAC.")
            adapter = filtered_adapters[0]
        else:
            print("Multiple Bluetooth adapters found: MAC filtering failed, using last enumerated adapter.")
            adapter = adapters[-1]
    elif len(adapters) == 0:
        print("No Bluetooth adapter found.")
        return

from adafruit_python_bluefruitle.

dhalbert avatar dhalbert commented on June 13, 2024

This library has been deprecated. Please update to use this new library:
https://github.com/adafruit/Adafruit_Blinka_bleio
If you continue to have this issue, please open a new issue in that repo.

from adafruit_python_bluefruitle.

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.