SimpleBLE icon indicating copy to clipboard operation
SimpleBLE copied to clipboard

Allow subscribing to Bluetooth state changes

Open naali opened this issue 4 years ago • 2 comments

I think it would be good to have a way to listen to changes in the bluetooth adapter state (Power on/off, Authorized, etc.). Since there is already a delegate for centralManagerDidUpdateState, adding the callback is quite simple.

I'm not sure whether Windows or Linux provide a similar functionality, but this PR should contain the necessary changes for MacOS.

naali avatar Dec 17 '21 11:12 naali

Hey @naali! Thanks a lot for your contribution!

One important thing to highlight is that a key design principle for SimpleBLE is to offer a consistent API across all operating systems. In order to add these new features as part of the stable API, we also need to have the Windows and Linux implementations available.

If you can help by doing some research on how this is done in Windows (I have more experience with Linux BLE, so I think that one should be quicker for me to implement) I would really appreciate it and it would also help the speed at which we can roll the feature out for all users.

kdewald avatar Dec 19 '21 07:12 kdewald

Excellent!

I’ll take a look at Windows next week.

naali avatar Dec 19 '21 16:12 naali

Hey @naali, how's it going?

Despite not being able to get exactly this feature in (there are some limitations on how these aspects are updated on Windows), I just landed on main a way in which you can manually poll the OS to check the status of Bluetooth: https://github.com/OpenBluetoothToolbox/SimpleBLE/blob/60d9388707aeaff107454d013a93616b5aecd513/simpleble/include/simpleble/Adapter.h#L42

This is the closest we can get for now, but I think it should do the trick.

kdewald avatar Sep 06 '22 04:09 kdewald