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 

  • Thanks Hung Bui,

    I will try this solution.

    Also, can you explain if i want to try the dynamic ATT solution ?

    How to define the service in this case and how to implement:

    // Set GATT database capabilities 

    // Set GATT service changed = 0100FFFF

    I was using SiLabs BGM113 MCU earlier for our previous BLE peripheral implementation and it was easy to implement GATT service change using a variable and their SDK API.

    Looks complex to understand this implementation in Nordic NRF Connect SDK

  • Hi Deep Patel, 
    I 'm on a business trip and will be back next week. If you need urgent support please create a new case and have a link to this. We will have other tech support to look into it. 

  • Hi Deep Patel, 

    Please find the attached example.  It based on the LBS example in SDK v2.0.0 . When you press button 2  on the DK it will register a new service. And when you press button 3 on the DK it will remove the service. You would need to do a service discovery every time the ATT table change. 


    It's pretty simple actually, simply calling bt_gatt_service_register() and bt_gatt_service_unregister() to add and remove service. 
    peripheral_lbs_dynamic.zip

  • Hello Hung Bai,

    Thanks let me look into this. Hope that suits my requirement.

    I am looking for a way to implement, so that reader peripheral can disconnect any open BLE connection with Mobile Client, stop advertising and start new advertising or no advertising based on input.

    For Example :

    Currently, Reader is configured with value '1' and it is advertising 'XYZ service'. Any mobile scanning this service can now connect.

    If reader gets a user input with value '2' .. i want the reader (peripheral) to disconnect with any open connections with Mobile Client, stop advertising 'XYZ service' and start advertising 'ABC service'

    Similarly, If reader gets a user input with value '0' .. i want the reader (peripheral) to disconnect with any open connection with Mobile Client, stop advertising 'XYZ service' and be idle (no advertisements)

  • Also, adding to my previous response : 

    " You would need to do a service discovery every time the ATT table change. "

    How do i do this ? Isnt it already enabled / included ?

    Also, CONFIG_BT_GATT_SERVICE_CHANGED Kconfig is required to be enabled ?

Related