Git Product home page Git Product logo

Comments (4)

ukBaz avatar ukBaz commented on September 25, 2024

This seems like is similar to #266 .

I suspect the issue is that the scanning is creating new devices in BlueZ which triggers the InterfacesAdded D-Bus signal. The observer code also removes those devices once it has the device information to work around a "feature" in BlueZ that throttles the reporting of discovered devices. Then the self.ble_uart.on_connect is using the same InterfacesAdded D-Bus signal.

So the investigation would need to focus on following section of code to make it more robust to the different scenarios where a InterfacesAdded signal is triggered.

def _interfaces_added(self, path, device_info):
"""
Handle DBus InterfacesAdded signal and
call appropriate user callback
"""
dev_iface = constants.DEVICE_INTERFACE
if constants.DEVICE_INTERFACE in device_info:
dev_addr = device_info[dev_iface].get('Address')
dev_connected = device_info[dev_iface].get('Connected')
if self.on_device_found and dev_addr:
new_dev = device.Device(
adapter_addr=self.address,
device_addr=dev_addr)
self.on_device_found(new_dev)
if all((self.on_connect, dev_connected, dev_addr)):
new_dev = device.Device(
adapter_addr=self.address,
device_addr=dev_addr)
self.on_connect(new_dev)

If you have any feedback or insight into how this could be changed (or tested) then please share.

from python-bluezero.

Severon96 avatar Severon96 commented on September 25, 2024

Thanks for the quick answer and your insight!
I have sadly no good idea whats the best way to adjust the code of yours. But if you have access to an ibeacon:
Create two python applications. One to advertise as BLE peripheral, one to scan for beacons.
When you start the peripheral application, use subprocess.Popen to start the beacon scanner.

This should be enough to reproduce my issues.

Until this issue can be fixed. What would be the best way to handle the thrown exceptions? I tried to wrap different parts of my code in try: except: blocks but nothing helped to catch them.

from python-bluezero.

ukBaz avatar ukBaz commented on September 25, 2024

From the start of this project there has always been a philosophy about complexity; that the library would attempt to help people along the learning curve as they learnt about using Bluetooth with Python and that for some they would outgrow the library as they wanted more control.

This meant that there was an acceptance that the abstraction would bring restrictions and that is why the concept of complexity levels was used. An interesting blog around this topic is "When you need to escape an abstraction, how violent is your exit?"

The observer and peripheral modules are at level 10 that looks to simplify event loops and so starts them in the background without the user knowing.

As a result of this the two applications want to create and start an event loop which means they have to run them in different processes to work. You have achieved this by using subprocess for one of them. However, that is not really how the event loop should be used. Both the "applications" should be registered to the same event loop and then the event loop started.

I have hacked together an example that starts just the one event loop:
https://github.com/ukBaz/python-bluezero/pull/381/files?diff=split&w=0

When I run the ticket_380 branch I don't see the errors that you are reporting.

I suspect that what this means is that you need to access the lower level API's to make your application(s) work cleanly.

from python-bluezero.

ukBaz avatar ukBaz commented on September 25, 2024

Closing because of inactivity.

from python-bluezero.

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.