-
Notifications
You must be signed in to change notification settings - Fork 118
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
Missing examples for reusable services #376
Comments
@jrobeson This issue has an incomplete or old issue template.For future reference please use an up to date clone of the repository before raising issues. Many thanks. |
Thank you for raising this detailed GitHub issue. I am now notifying our internal issue triagers. |
Hi @jrobeson, The Mbed BLE services working group has been working on this for the past few months. We've been trying to come up with a robust framework for creating new services and integrating BLE as a modular subsystem. This work has been mostly done in the mbed-os-experimental-ble-services. There, you can see the current state of how we envision creating modular/reusable BLE services. We'd love to get your feedback! |
the services seem fine, but the only example of their usage is in the tests, which only do BLE stuff. I just wanted to see something that assumes you already have a working application of some level of complexity (even if it's not shown in the example) and wanted to integrate BLE into it. |
Not sure what this kind of example would need to look like. The existing examples are extremely simple and if you want to embed them in an existing application all you have to do is rename the main function into run_ble function and call it from your application. |
@paul-szczepanek-arm As you pointed out in that case one just needs to rename
I know this might sound like trivial for anyone who has some experince with BLE but for those who just start to learn implementing BLE there are way too many pitfalls currently (mainly because of the language of the doc. You need to read it 1000 times before you begin to understand some parts of that as a newcomer, though even the current doc may be good enough for BLE experts who only need some refresher). |
Not official team position, ask @pan-, but I don't think we're here to teach developers about BLE. There is already an extraordinary amount of resources that can teach you about BLE in general, how it works, etc available for free on the Internet. Not least on the official website: https://www.bluetooth.com/bluetooth-resources/bluetooth-le-developer-starter-kit/ |
I ended up working out my problem by going line by line. However, I still think there's a bit of confusion regards to where onDataWritten and other similar events happen. I see that chainable GAP handler happened, but it's not really well used. It'd be nice to see best practices about when and whether to use the chainable gap handler and where best to handle onDataWritten and similar events and make sure my own isn't clobbered or becomes clobbered by the services I used. They might be clobbered by either mishandling the events, or simply because they got overwritten. @paul-szczepanek-arm that |
@paul-szczepanek-arm While i might relative new to BLE i am sure @jrobeson has way more experience with BLE than you think. In case he does not understand something, it does not mean the problem must be on his side. Just watch what else he might still find if he digs deep enough 😉 |
@jrobeson
See the Mbed-os-experimental-services repository for examples of the current best practices we have developed. Many of the services I've started to develop follow closely to the structure of the ones in that repo. They are designed to be flexible, modular, and lightweight. The focus of the BLE stack and services is on communication rather than figuring everything out for you. The example services leave a lot of the logic decisions up to the application to accommodate a variety of use cases.
I think that many, many, BLE stacks out there that are easy to use trade off flexibility and access to more advanced features of BLE. I've used some of the other stacks out there and things are a lot more "canned". Sure, they have end to end examples but good luck shoehorning that into your actual application. I think the Mbed team has done a fantastic job making a well-tested, performant, and modern BLE API/implementation. BLE is much different from its first iteration and Mbed has made it possible to use many of the new features (eg: extended advertising, different PHYs, etc)
I agree with you here, I think the documentation could use some help. The same goes for examples. I think ARM should hire some entry-level, possibly even freelance technical writers to do how-to articles and getting started guides. Having these available would drastically reduce the learning curve. I think there might be a misunderstanding -- @paul-szczepanek-arm is very polite person. His tone may be getting lost in the text (use more emojis, Paul 😁). I don't think he meant any offense to you. We gladly welcome contributions and questions. Please put questions on the forum and reserve GitHub issues for actual bugs. I haven't read back far enough to see what your issue is, but whatever you're trying to do I would be happy to point you in the right direction. P.S. |
@idea--list We are reworking the documentation to provide content which we think is more relevant to our audience. While doing this we stated goal for the documentation: it should explain how to use the Mbed OS API. It is not a place to explain how the Bluetooth protocol works in detail. There are other great resources available for that. To make an analogy, you wouldn't expect a socket library documentation as a reference to IP protocols that it offers but you expect from it to explain you how to use them in your application. Following this we want to add more useful content around the use of the API. For example, how to optimize an application for throughput, how to optimize an application for power, how to debug, ... If you have more suggestion, we are happy to review them.
@jrobeson We have one repository open where we explore how we can improve the experience when Bluetooth is used: https://github.com/ARMmbed/mbed-os-experimental-ble-services . A standard way of describing a service is key if we want to offer some service management latter on. For now, you can look at how the BLE_GattServer_ExperimentalServices example uses the reusable LinkLoss and CurrentTime services. |
@pan- Until the reworked doc i will just rely on BLEIntros i mentioned in another topic as i find it miles better than the current one. The more i read it, the less it seems to be deprecated as i initially thought. |
@jrobeson this issue appears to have broadened in scope. Can you clarify what you think is broken? Just going by the title, there is an example for reusable services: If there are particular problems you are facing with your applications feel free to ask about those. |
I think that one does does cover my initial problem. I honestly ignored that specific one because it has the word experimental in it. I guess the last issues i have will be covered as mbed-ble-utils stops dispatching events by itself, so it can be used freely in another application and once the examples converge on the same style and usage of BLEProcess vs BLeApp and the ones that don't use any of the common code from mbed-ble-utils. |
I was just browsing the mbed discourse and saw this, so I"m not the only one with similar problems https://forums.mbed.com/t/ble-proper-way-to-add-several-services/13628 |
So it is clear from our discussions that even the Mbed team has not yet established "best practices" for making complex BLE apps. Therefore, I think we should all work together with this understanding in mind. The pattern I currently use in my apps pretty much has the following:
Typically, services have their own EventHandler type that a user can register a handler for. All application logic goes in this handler. The service primarily is concerned with BLE communication rather than acting on the data passed through it. This has been the most flexible way to structure a BLE app so far that I have found. It does have a lot of code duplication between projects that I think a proper framework could encapsulate. |
Yes, not all examples have been upgraded to BleApp but both BLEProcess and BleApp are there just to make the examples simpler. They are not meant for production code. All the examples here are not meant for production code. Each examples tries to teach you one thing. A basic one one like the advertising one will show you how to set up the ble instance and run advertising. An example for subscription will concentrate only on that - avoiding duplicating the code as its goal is to only show you how to do one thing - subscribe to updates. At some point this year (I hope) we'll publish a production ready BleApp and I will convert most examples to use that. I will still leave some examples setting up the instance manually to show how that is done in case you don't want to use the BleApp. |
That can easily be fixed by providing a flag in the @AGlass0fMilk What you described would be the best practices minus when using Mbed BLE and that is what we're converging to in the experimental service. |
@paul-szczepanek-arm , @pan- If i am right there are 6 different approaches to program BLE logic: IMHO it would be worth putting all the info of the last few comments here into the readme of this repo, that would help to cut through all the confusion one might face without these info. |
Description of defect
Previously this repository contained services that one could easily look at to see how they could be reused in your own code (like the LED service).
Now all the examples seem to have code in which the application is tied up with the service itself, so I can't figure out how standalone resuable services are supposed to look anymore.
I'd like to see an example in which BLE is just one aspect of the program, but doesn't dictate the application itself.
I went from the blinky examples to a BLE enabled app by comparing blinky with those previous examples by comparing them.
Maybe the problem is just that I don't know how to migrate from something that looked like the old code that didn't use the new ble helper library to the new ones that do.
What version of the example and mbed-os are you using (tag or sha) ?
6.x
The text was updated successfully, but these errors were encountered: