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

How to tell which service is connected from the BLE event parameters of nRF51 peripheral

I have several services on a nRF51 peripheral, and would like to have different initialization based on which service is being connected to. The related code is below:

static void on_ble_evt(ble_evt_t * p_ble_evt)
{
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
		    ......
			break;
		case BLE_GAP_EVT_DISCONNECTED:
		    ......
			break;
		case ...
		     ......
		default:
		    break;
	}
}

However, I don't know how to associate the BLE event with a specific active service. Please advise. Thanks.

Parents
  • Hi,

    I assume that you want to turn off unneeded hardware and services, so that your device is not wasting resources and powering hardware it does not need. If this is not the case, or if you have more details on what you are doing and what is your goal, feel free to extend your question or explain further in the comments.

    As already answered by Wojtek, you can not know at the time of connection what services is of interest to the central. There is no mechanism in BLE for knowing this on initial connection.

    What you can do, is to wait for the central to read a characteristic (thereby knowing the service containing that characteristic is of interest). You can also set up your characteristics with notification, and rely on the central to enable notifications on the characteristics of services that it wants to use.

    Depending on your application you may also consider to make a service designed to select what other services should be updated, or to include with your services a characteristic to enable/disable the service. Do note that these last options would not work with standard services and/or generic centrals, so if used they should be reserved for your own custom services only.

    Regards, Terje

Reply
  • Hi,

    I assume that you want to turn off unneeded hardware and services, so that your device is not wasting resources and powering hardware it does not need. If this is not the case, or if you have more details on what you are doing and what is your goal, feel free to extend your question or explain further in the comments.

    As already answered by Wojtek, you can not know at the time of connection what services is of interest to the central. There is no mechanism in BLE for knowing this on initial connection.

    What you can do, is to wait for the central to read a characteristic (thereby knowing the service containing that characteristic is of interest). You can also set up your characteristics with notification, and rely on the central to enable notifications on the characteristics of services that it wants to use.

    Depending on your application you may also consider to make a service designed to select what other services should be updated, or to include with your services a characteristic to enable/disable the service. Do note that these last options would not work with standard services and/or generic centrals, so if used they should be reserved for your own custom services only.

    Regards, Terje

Children
No Data
Related