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
  • Hello Hung Bai,

    Probably the end user using the mobile phone application (GATT Client), will only see the service which it is looking for.

    But. for testing purposes i am using nRF Connect  Mobile App as a sniffer (scanner), and that sees all services and their characteristics (not related to the advertiser) defined in the GATT Server database, which i don't want to be exposed. Let me look into your example if that helps me.

    Thanks.

Reply
  • Hello Hung Bai,

    Probably the end user using the mobile phone application (GATT Client), will only see the service which it is looking for.

    But. for testing purposes i am using nRF Connect  Mobile App as a sniffer (scanner), and that sees all services and their characteristics (not related to the advertiser) defined in the GATT Server database, which i don't want to be exposed. Let me look into your example if that helps me.

    Thanks.

Children
  • I would suggest to also look at this library: \zephyr\subsys\bluetooth\mesh\pb_gatt_srv.c

    In the library we use CONFIG_BT_GATT_DYNAMIC_DB and use bt_gatt_service_register() and bt_gatt_service_unregister() to update the ATT table. 


    But as I mentioned, this will cause more complex situation when the phone may confuse with the current ATT table if it's not properly handled. So to make it more simple and robust I would suggest to keep the ATT table static. 

Related