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

Creation of a secondary service?

I'm trying to write a test service on a PCA10001 that transmits a single scalar value that is computed from a few different sensor readings. I would like this service to send a notification when the scalar is outside a set range. The set/combination of sensors can vary from device to device, but I'd like the code to be as generic as possible.

My design approach would be to advertise the combined scalar as a primary service and each individual sensor reading as a secondary service.

My question is if there are any examples in the application notes, support material that show how to implement a server that provides a similar combination of services.

  • Sorry for the late response. If it's the requirement form your peer device (the client) that you must have a fixed list of primary services. Then it makes sense to have your unique services as secondary services. But for most use cases we know of, we can simply set all of the services as primary services. There maybe one use case, I can think of, is when you want to reduce the time needed for service discovery, so that only primary service is discovered and leave the secondary to be discovered later if needed. We do have secondary service supported with our S110 stack. When you add a service you would need to set the service type as BLE_GATTS_SRVC_TYPE_SECONDARY when calling sd_ble_gatts_service_add() and have to refer to that service from a primary service using sd_ble_gatts_include_add(). Unfortunately, we haven't got an example for that, we will try to make one.

  • Thank you for reply, very helpful. Just to be on the same page. There is no requirement for the fixed list of primary services. Client always needs to know the temperature in my example. The combine temperature is different for different devices and depends upon number and location of sensors. This configuration may be requested only if needed.So, does it make sense to have various primary services if in majority cases the combine temperature is sufficient. I don't have enough experience to decide and hope that you do. Thanks again.

  • Thanks so much for the response! That was helpful.

  • Nobody said that fixed list of primary services is a must. I was saying that one of primary services is common for entire family of devices and every family member has its unique services with logical ties to that common primary service and it MAY make sense to implement them as a secondary. Your opinions/suggestions are welcome. Thanks.

  • @Michurin: You would need to let me know more detail on your central device. Do you have control over the stack of the central device ? or it's common central such as a phone/tablet ? As mentioned before, I don't see any draw back to declare all of your service as primary service except for the longer discovery time. If you have control over the central stack, you can reduce this discovery time by stop discovery when you has found the primary service you want.

    Please be noted that not all central stack have full support to automatically discovery secondary services (e.g S120 stack).

    So, still, my suggestion is to declare all of your services as primary services.

Related