Hi All,
Just wanted to give an update to the community on the status of trying to
start the GATT server after the OS is initialized.

to ble_hs.c
@@ -606,5 +603,7 @@ ble_hs_init(void)
     /* Configure the HCI transport to communicate with a host. */
     ble_hci_trans_cfg_hs(ble_hs_hci_rx_evt, NULL, ble_hs_rx_data, NULL);

+#if 0 /* Let the Application set the queue and start the BLE stack */
     ble_hs_evq_set(os_eventq_dflt_get());
+#endif
 }

Then, I just have to call ble_hs_evq_set() with my ble thread's queue after
registering my GATT services.

The next thing I need to figure out though, is how to remove registered
GATT services and add new ones after the GATT server has started.
I think ble_hs_sched_reset() might work, if I move its function definition
from src/ble_hs_priv.h to include/ble_hs.h.
I haven't tried this out yet though. Will get to it soon.
Thanks,
Pritish

On Tue, May 2, 2017 at 6:26 AM, Wayne Keenan <[email protected]> wrote:

> 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 <[email protected]> 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