Apologies, I missed this (email and generally in the 1.0 dev) but please do
support this, as it's pretty much a mandatory requirement for being able to
create GATT services (and set-up advertising data) after the OS started,
using an embedded scripting language.



Thanks,
Wayne

On 28 April 2017 at 00:05, Christopher Collins <ch...@runtime.io> wrote:

> Hi Pritish,
>
> On Thu, Apr 27, 2017 at 03:49:34PM -0700, Pritish Gandhi wrote:
> > Hi All,
> > I have a generic question about the nimBLE capabilities. I'm trying to
> > build a BLE GATT server which has a set of services (say services A and
> B).
> > However, these services need to be registered dynamically. What I mean is
> > that when I boot up I won't know which services I need to register with
> the
> > GATT server. I'd like to boot up, probe around a bit, and then make a
> > decision on whether I want to register and then advertise either service
> A
> > only, service B only, or both.
> >
> > However I'm not quite sure I see a way to do that. It seems like services
> > need to be added and registered before the os runs.
> >
> > Here's what the comment says in ble_gatts.c
> > /**
> >  * Queues a set of service definitions for registration.  All services
> > queued
> >  * in this manner get registered when ble_hs_init() is called.
> >  *
> >  * @param svcs                  An array of service definitions to queue
> for
> >  *                                  registration.  This array must be
> >  *                                  terminated with an entry whose 'type'
> >  *                                  equals 0.
> >  *
> >  * @return                      0 on success;
> >  *                              BLE_HS_ENOMEM on heap exhaustion.
> >  */
> >
> > Is what I'm expecting to do not possible?
>
> What you're expecting is almost possible, but it is not a use case that
> the host API allows.  The issue is that host starts itself as soon as
> the OS is started, at which point it is too late to register additional
> GATT services.
>
> There is a fairly simple hack that I believe should make this possible:
>
> 1. Modify ble_hs_event_start() (ble_hs.c) such that it is a no-op:
>
>     --- a/net/nimble/host/src/ble_hs.c
>     +++ b/net/nimble/host/src/ble_hs.c
>     @@ -388,10 +388,12 @@ ble_hs_event_reset(struct os_event *ev)
>      static void
>      ble_hs_event_start(struct os_event *ev)
>      {
>     +#if 0
>          int rc;
>
>          rc = ble_hs_start();
>          assert(rc == 0);
>     +#endif
>      }
>
> 2. Call ble_hs_start() from your application after you have finished
> registering services.
>
> This seems like a pretty useful behavior, so it might be worth making
> this configurable in future versions.
>
> Chris
>

Reply via email to