OpenBluetoothToolbox / SimpleBLE

SimpleBLE - the all-in-one Bluetooth library for MacOS, iOS, Windows, Linux and Android.
https://www.simpleble.org
Other
675 stars 115 forks source link

[Python] Application error with multiple devices and subscriptions #290

Open bradmartin333 opened 7 months ago

bradmartin333 commented 7 months ago

Stuck battling a multi-device application crash. Found a fix, but it requires running 2 instances of the same application. Not sure where the issue lies. Let me know if I am being too vague / more info needed.

Pseudocode

main starts new thread with a target that performs something like:

adapter = get_one_valid_adapter()
adapter.scan_for(5000)
peripherals = adapter.scan_get_results()
# device_a
device_a, service_uuid_a, characteristic_uuid_a = find_connect_device_a(peripherals)
device_a.notify(service_uuid_a, characteristic_uuid_a, lambda data: print(f"Notification: {data}"))
# Repeat for a hypothetical device_b

I have also tried:

# device_a
adapter = get_one_valid_adapter()
adapter.scan_for(5000)
peripherals = adapter.scan_get_results()
device_a, service_uuid_a, characteristic_uuid_a = find_device_a(peripherals)
device_a.notify(service_uuid_a, characteristic_uuid_a, lambda data: 
print(f"Notification: {data}"))
# Repeat for a hypothetical device_b

Issue

Screenshot 2024-02-13 060725

Working solution

Questions

Jah-On commented 3 months ago

I'm also experiencing a similar issue on Windows where the whole app silently exits upon trying to process a notification.

Jah-On commented 3 months ago

I'll try writing a C++ version to see if it's the Python FFI or something in the C++ back end.

Jah-On commented 2 months ago

This appears to be an issue related to FFI as notifications in C++ work fine.