win32
win32 copied to clipboard
Bluetooth Low-Energy Samples
Hey,
I saw that BTLE is now part of win32 and that's super exciting. From reading the documentation though, it seems like there isn't an example on how to subscribe to characteristics or equivalent.
Is this possible with the existing implementation, and if so, would you accept a PR with an example that shows how to subscribe to BTLE characteristic notifications? If so, I might need some rough notes on how this works so I can do a sample up.
Hi there! Thank you for the request. Yes -- you're very welcome to submit an example of this, but I have very little knowledge of implementing Bluetooth LE myself, so unfortunately I can't give you much in the way of pointers.
My focus with this project is projecting the underlying Win32 / COM APIs to Dart, but there are too many different subsystems for me to myself be an expert in all of them. You might look for a C/C++ example that you can port over, whether in the Microsoft documentation or elsewhere. If you submit something that is based on another example, please include a link to the original example in your pull request, and make sure that it's OSS-licensed, so that I can include the relevant acknowledgements in the readme.
Thanks for that Tim. I think I've found some doco here which I can consult: https://docs.microsoft.com/en-us/samples/microsoft/windows-universal-samples/bluetoothle/
Frustratingly, a lot of links on the page are returning "access denied". But there's still a sample I can reference, which I can try to make work. I think @Sunbreak is trying to implement this as well for his quick_blue package, so I'll keep an eye on that repository as well.
Thanks for that Tim. I think I've found some doco here which I can consult: https://docs.microsoft.com/en-us/samples/microsoft/windows-universal-samples/bluetoothle/
It is an example of UWP APIs of BluetoothLE, which quick_blue uses right now. Windows 1703+ acquired
I have done some examples on win32 APIs of BluetoothLE. But I wouldn't recommand using them
It is quite cumbersome to find nearby BluetoothLE devices via win32 APIs: https://stackoverflow.com/questions/54912411/detecting-ble-device-in-range-on-win32
If you're interesting in handling WM_DEVICECHANGE, take a look at https://github.com/woodemi/quick_device_watcher
Or you could reference Chromium project: https://chromium.googlesource.com/chromium/src/+/HEAD/device/base/device_monitor_win.cc
So, before this, I was creating a WPF app with BLE functionality but I much prefer using Flutter for the UI and other reasons. The reason why I have begun this journey is because I really want to use (and contribute) to a stable and reliable BLE solution for Flutter because I have a hobby app that uses BLE quite significantly.
So, to that end (and this might not be the best place for these questions, but I'll ask anyway...). These may be really stupid questions so I appreciate the patience. I'm really blazing the trail with Flutter on Windows here because I really want to create desktop apps with native functionality.
- When we talk about UWP API's, I take it the are different to win32 API's? So, we can't leverage the BLE UWP API's from this project anyway, because they're not part of the win32 API?
- Following on from above, we can technically use win32 for BLE, but it's much more complicated and involved than just using the UWP API's?
- If Win32 API's are projectable via this project, does that mean that UWP API's are projectable as well? And, is that something that might happen in the future?
@Sunbreak I currently use quick_blue in my project and it works well, but it crashes occasionally and when it does it doesn't produce usable errors. Android Studio just says "Lost connection to device" and nothing is logged that I could even create a GitHub issue with. I've cloned quick_blue and attached it to the running app but I've not been able to work out why my crash is happening or what to do about it.
Some disclosure: I'm a C#/.NET developer and I understand that C++ is a totally different beast. But I really want to understand it so I can contribute to BLE functionality with Flutter on Windows.
- When we talk about UWP API's, I take it the are different to win32 API's? So, we can't leverage the BLE UWP API's from this project anyway, because they're not part of the win32 API?
- UWP APIs are differrent from win32 APIs. And we could use most of UWP APIs via
C++/WinRT: https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance
2. Following on from above, we can technically use win32 for BLE, but it's much more complicated and involved than just using the UWP API's?
- Technically yes. But not worth. UWP APIs (or WinRT APIs) are much better
3. If Win32 API's are projectable via this project, does that mean that UWP API's are projectable as well? And, is that something that might happen in the future?
- This project, i.e.
win32Dart package, is working on Dart projection on WinRT as well:- https://github.com/timsneath/win32/pull/259
- https://github.com/timsneath/win32/pull/406
- When projection on WinRT done, we could call WinRT API via
dart:ffi
@Sunbreak I currently use quick_blue in my project and it works well, but it crashes occasionally and when it does it doesn't produce usable errors. Android Studio just says "Lost connection to device" and nothing is logged that I could even create a GitHub issue with. I've cloned quick_blue and attached it to the running app but I've not been able to work out why my crash is happening or what to do about it.
https://github.com/woodemi/quick_breakpad may help. We'd better open another issue on quick_blue repo