This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to know when database discovery is finished?

I am using the database discovery module in my app (my code is based on the "HRS client" that is one of the SDK examples). I am able to discover multiple services (both custom and adopted) from the remote device just fine, but this part is unclear: how do I know when the entire database discovery procedure has been finished? 

To be a bit more specific, I first register the services that I am interested in by calling ble_db_discovery_evt_register() one or many times. Then I kick off the service discovery by calling ble_db_discovery_start(). 

After starting, I will get a series of events, type being BLE_DB_DISCOVERY_COMPLETE, BLE_DB_DISCOVERY_SRV_NOT_FOUND etc.. So far so good.

Now the question is: how do I know that the discovery state machine has gone through all the services in the list? I could not find any event to indicate this. I need to know when the discovery is complete so that I can continue with other tasks in my application (e.g. read some of the characteristics in the remote database).

I could of course count the number of events triggered by the discovery module and compare it against the number of services I have registered, but that sounds a bit clumsy. There must be some more elegant way to do this?

Any pointers appreciated.

Related