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

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

Open
bradmartin333 opened this issue Feb 12, 2024 · 0 comments
Open

Comments

@bradmartin333
Copy link

bradmartin333 commented Feb 12, 2024

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

  • device_a's characteristic notifies at 250Hz and device_b notifies at 1Hz. The data sometimes seems to get jumbled and the python program abruptly exists with no exceptions whatsoever across all main and dummy threads.
    • By jumbled, I mean I will start getting crc16 check errors where I haven't seen any before with a single device
  • The only indication that there was an error is in the Windows event logs. I have not tried on Linux, yet.

Screenshot 2024-02-13 060725

Working solution

  • Now, I run 2 separate python programs with identical code but for only one device and that works
  • I have a single Bluetooth 5.0 adapter on Windows

Questions

  • Is this the intended behavior?
  • Could it be an issue with spawning a thread to discover and connect?
@bradmartin333 bradmartin333 changed the title [Python] Application error exit with multiple devices / subscriptions [Python] Application error exit with multiple devices and subscriptions Feb 12, 2024
@bradmartin333 bradmartin333 changed the title [Python] Application error exit with multiple devices and subscriptions [Python] Application error with multiple devices and subscriptions Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant