How shall i define multiple services in GATT Server database, so that only 1 service is seen by GATT Client at a time ?

I am developing GATT Server Reader Firmware usng nRF SDK COnnect using NRF52840

I have implemented two services in reader FW in two files say: service_a.c and service_b.c

Both files have their respective GATT attribute table.

Both have their advertisement packet defined but only one is advertised based on user input.

Example scenario : Reader is advertising service a, when user inputs 1 to reader.

Reader changes its advertisement to service b, when user inputs 2 to reader.

Now, when user enters 1, mobile sees service a advertisement and it connects with reader.

Problem is .. when Mobile connects with Reader .. it sees service a as well as service b both !! 

How do i only expose service a when connected via service a advertisement and not the other ?

Example declaration of my both services in seperate files 

Parents
  • Hi Deep Patel, 

    It's actually possible to do so. You can have a look at gatt pool library here. I haven't used it myself but as far as I can see you can find en example of using it inside \nrf\subsys\bluetooth\services\hids.c 

    Note that changing the attribute table dynamically requires you to send a service change indication to tell the peer device (the phone) to do a service discovery to update the table. 

    Normally in many application we use fixed attribute table. Meaning if the service is not needed for the operation you simply keep it there and remove any function on the service. This normally doesn't affect the end user. In most case you have your own app on the phone that can hide the service that is not needed for certain mode of operation. Most of the time the end user wouldn't be able to see the service/characteristic in raw. 

Reply
  • Hi Deep Patel, 

    It's actually possible to do so. You can have a look at gatt pool library here. I haven't used it myself but as far as I can see you can find en example of using it inside \nrf\subsys\bluetooth\services\hids.c 

    Note that changing the attribute table dynamically requires you to send a service change indication to tell the peer device (the phone) to do a service discovery to update the table. 

    Normally in many application we use fixed attribute table. Meaning if the service is not needed for the operation you simply keep it there and remove any function on the service. This normally doesn't affect the end user. In most case you have your own app on the phone that can hide the service that is not needed for certain mode of operation. Most of the time the end user wouldn't be able to see the service/characteristic in raw. 

Children
No Data
Related