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

Event for Service Discovery

I was wondering if it would be possible to add an event for Service Discovery (and other similar BLE stack events) that could be detected by user applications. Per answers such as here and here, it looks like that isn't enabled in the softdevice currently.

The application I'm working on uses the nRF51822 on a power-constrained device. It's very important to minimize current draw, both average and instantaneous. I use events for things like the start of a connection or read authorization as a trigger to temporarily stop other system functionality (such as UART transmissions) while BLE is dominating the power budget. It would be very useful to be able to detect when the softdevice is performing interactions such as Service Discovery in order to act upon that knowledge and limit my power use. Similarly, it would be helpful, although less necessary, to get events when those actions have completed.

As it is, my device occasionally overwhelms its power budget and crashes when a central performs Service Discovery.

  • I was about to post a similar question, albeit for my question what I need is to know when a Service Discovery has been completed.

    I realize I could do a blocking wait or a periodic check of the ble_db_discovery_t.discovery_in_progress. But blocking obviously block the code for who-know-how-long, and periodic check would waste a timer channel just for one purpose.

  • can you use the radio events callback as a sort of weak proxy to know when the softdevice is doing something? Or is that too coarse grained? You could even mix that with the suggestion to check discovery_in_progress without using a timer or blocking and that might give you a reasonable window to turn things off.

  • I might misunderstand you here. Do you mean adding the detection code to the method ble_evt_dispatch() in main.c?

    As I am looking for when the discovery process end, I fear that might not work.

    In the discovery process, the last BLE_GATTC_EVT would trigger the code to set discovery_in_progress to false. Unless I am missing something, there could be the case where there are no BLE event sent after that. In such case, the discovery complete detection code would never be ran.

  • radio events go on all the time, constantly, so you'll always get more of them and you can check the flag until you get a radio off notification and find the flag is now false. You may wait an extra cycle, but you won't miss it and the code will be run.

  • I didn't really clarify in my question, but I'm looking for this capability for peripheral devices (s110/s130). A notification when the central begins/ends discovery of my services.

    @vthieu, are you looking for the capability for a central device? (s120/s130) Is it possible to check the discovery_in_progress flag on the s110?

Related