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 .

    What do you mean by your statement : 

    "Meaning if the service is not needed for the operation you simply keep it there and remove any function on the service"

    Please explain in detail.

    I dont mind having a static ATT table (with two or more service definitions .. example Service A, Service B, etc)

    Just want to know how to keep things in code,

    such that if USER A Mobile Client.. when connected for Service A, if by accidentally it tries to access (read / write) Service B, what to do ?

  • Hi Deep Patel, 

    What I meant was that you keep the declaration of different services in your device. 

    Then you can define different "states" of operation where a service would operate or not. 

    So in the code of a service you can have an "if" to check the state, if the state is "A" for example then you will return the correct value in a read call back, or do notification etc. If the state is "B" then you will not return correct value and only return 0. And you don't do any notification, don't react to a write command etc. 

    On the opposite, with another service, the behavior can be different, you react correctly if the state is "B". 

    You can use event module to notify to the service about different state changes. 

  • 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)

Reply
  • 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)

Children
No Data
Related