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

Autoconnect w/ multiple devices? #96

Closed
snhirsch opened this issue Jan 8, 2024 · 3 comments
Closed

Autoconnect w/ multiple devices? #96

snhirsch opened this issue Jan 8, 2024 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@snhirsch
Copy link

snhirsch commented Jan 8, 2024

I'm not sure if this is a bug or the intended behavior. I have two HM-10 devices active and have created a section in the autoconnect.ini file for each. One gets associated with the BLE virtual port and the other with BLE2. I have created both port pairs: BLE<-->COM7 and BL2<-->COM8. Both work individually if I connect manually, but with the autoconnect.py script only one of them (seemingly at random) is ever connected. After the connect it announces that it's entering the main loop and that's it! Shouldn't it continue the scan and also pickup the other device? Or, am I misunderstanding the purpose of the program?

@Jakeler
Copy link
Owner

Jakeler commented Jan 9, 2024

It's intended behavior for the basic implementation, the scanner stops while a device is connected and only resumes afterwards. There was never much interest in the autoconnect tool, so a multi device feature was never requested there and I didn't touch it for almost 3 years.
That being said, the architecture with asyncio tasks should work well with multiple subprocesses, it's probably enough to remove the scanner stop line. Some extensions are needed just to make this more practical.

  1. connected devices can show up again as scan result, to avoid multiple connections with the same device it should track connected devices and filter the scans against it.
  2. currently logs from ble-serial are passed into the same terminal, this would get messy and confusing with multiple runs in parallel. An idea is to prefix each line with a process/device id. Or always capture it and write into files. Or use some external terminal multiplexer like tmux, multiple terminal tabs/windows etc. this would be nice, but very OS specific, also makes (1) more difficult with the wrapper not immediately returning or not passing the exit code.

@Jakeler Jakeler added the enhancement New feature or request label Jan 9, 2024
@snhirsch
Copy link
Author

snhirsch commented Jan 9, 2024

Thanks for the explanation! I looked at the code briefly and it doesn't look too bad to implement what you suggest. I am not familiar with Python threading, but I assume it has all the "usual" primitives for inter-thread serialization. Does the runtime quantize print output by line? If so, then your suggestion for prefixing the lines will be fine. I'd prefer them to be labeled by endpoint (e.g. BLE, BLE2, etc) since that's better for human interpretation than MAC addresses. Given the need for cross-platform support, the simpler the better.

@Jakeler Jakeler added this to the 3.0.0 milestone Dec 7, 2024
@Jakeler
Copy link
Owner

Jakeler commented Dec 9, 2024

I went with the prefixing line approach. There is now a name config option so you can set it to whatever you like.

It required a few more changes because connections fail when the scanner runs continuously, the scanner has to stop for some time (-t parameter) to let ble-serial startup. Then it listens again for other devices. Successfully tested with two at the same time.

You can try it with the new 3.0.0 release.

@Jakeler Jakeler closed this as completed in 0d1dea5 Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants