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

Startup requirements in Linux #184

Open
xeanhort opened this issue Aug 7, 2023 · 4 comments
Open

Startup requirements in Linux #184

xeanhort opened this issue Aug 7, 2023 · 4 comments

Comments

@xeanhort
Copy link

xeanhort commented Aug 7, 2023

Hi, I'm having an issue with a code that uses this library running in Raspberry.

The code works properly if I start it once the system has been turned on for a few minutes. If I run the code with systemctl (After=bluetooth.target) it returns 0 BLE devices when scanning, but there is no error returned in any of the library functions.

I'm not sure if I should wait for a different service (other than bluetooth.target), but I think the library should be aware that is not "scanning properly" and return an error if it fails.

Thank you

@TirelessDev
Copy link
Contributor

This is a problem on macOS and presumably Windows as well. Not so much the boot-up race condition, but the ability to check the adaptor status at run time which would provide a means of working around this.

On macOS at least you will receive an error when calling adapter.Enable() if the Bluetooth adapter is turned off but on Linux it seems to just continue happily, at least on Raspbian. There is also no way to tell after calling Enable() if the adaptor has been turned off or something else funny has gone on causing the adapter to stop scanning. The capabilities exist on the macOS cbgo side to expose notifications about the adaptor state but it's not as clear how this will be done on the Linux side.

Unfortunately, I don't have the ability to explore this on Windows or bare metal. However, I suspect on the bare metal side this is largely a non-issue.

@deadprogram what are your thoughts on exposing adapter state updates?

I will do some digging.

@ansoni-san
Copy link
Contributor

I have a need for this also.

I have hacked around it for the time being as I wasn't sure about the design decisions, and because probably I'm the wrong person as I would immediately want a fully event-based interface for this project. Needs a longer-term understanding of the design decisions behind the current interface.

I forgot that I also really want this 🤔

@TirelessDev
Copy link
Contributor

A full event-based system would be nice, but given that the interface needs to be efficient for bare metal targets I expect it would be a bit much. My plan is to implement it as a simple callback on adapter state change. This is the same interface approach used for the GAP connect handler and scanning callback.

@aykevl
Copy link
Member

aykevl commented Aug 29, 2023

I've found systemd to be rather confusing, and dependencies don't always do what you'd expect. I guess the Bluetooth service isn't fully started (BT adapter powered on and all) before your custom service starts.

Here is something that may or may not help (I'm still confused after reading these descriptions, they seem way more vague than necessary):
https://serverfault.com/questions/812584/in-systemd-whats-the-difference-between-after-and-requires

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

4 participants