How to add add, insert and remove BLE services dynamically at run time and if I have to send multiple data under one service

if I have to send multiple data under one service 

like: Service 1(Information)

Hardware Revision String

Model Number String, the

Regulatory Certification Data List 

Then what should be the proper format (like string, array, individually or something else) of sending data? 

Parents
  • Hi Ayu,

    Any data sending over BLE is a byte array. 

    So you can either make different characteristic for each of the data you want to send. Or you can use one single characteristic and send all data via this characteristic. 
    You can simply use the first byte in the array to tell which type of data containing in the array. 

  • Ok, but you missed first question, that 

    How to add add, insert and remove BLE services dynamically at run time

  • Hi Ayu, 

    You only need service changed indication if you update the attribute table when you are already in a connection. 

    To do that, you would need to the service changed characteristic (included by default) then you need to call sd_ble_gatts_service_changed() to send the indication. 
    Please take a look at this ticket: RE: I give up; how do I do a service changed? 

    The example  you should have a look is ble_app_gatts

  • Hi Hung, thanks for last response,

    1- Currently I have used two dks one for peripheral and one for client but I am not able to understand the seral monitor result. Can you explain.

    2- And how to do same by  nrf connect app and dk.

    3- So, what I am understanding is  when ever I am clicking button 3, a new service is getting created and client is discovering it with NRF_BLE_GATTS_C_EVT_DISCOVERY_COMPLETE and then notify that service changed received with NRF_BLE_GATTS_C_EVT_SRV_CHANGED. But let say I don't want click the Button 3 or any button and want to add services on peripheral side dynamically then how to do this. any reference or example?

    Peripheral Outputclient

  • Hi Ayu, 
    Sorry for late response. We are under reduced staff in the summer. 

    1. Please study the code and check where the log is printed. 

    2. Please verify if you can add new service by using a phone to see after you add a service would you have more service when you disconnect and then connect. 

    3. I don't really understand you. If you don't want to click a button, you can change the code to do it based on something else, timer or other event. I don't see any limitation on why you can't change that. 

  • Thanks  , I understood the output. Also I am able to add custom services and characteristics dynamically. But still every time I need to refresh the nrfconnect application to see the newly added characteristics. Can I automate it, can I send any notification that new characteristics has been added, so that app can refresh it.  I want to know about peripheral side rather than client(mobile) side. Can you please help me in this.

  • Hi Ayu, 

    There is a button in NRF Connect called "Refresh service" (click on 3 dots) you can click that to have the service discovery again. 

    If you develop your own app you can automate it.

    Have you sent service changed indication ? If you did, I believe you can get the indication from the app and can automatically do service discovery again. 

Reply
  • Hi Ayu, 

    There is a button in NRF Connect called "Refresh service" (click on 3 dots) you can click that to have the service discovery again. 

    If you develop your own app you can automate it.

    Have you sent service changed indication ? If you did, I believe you can get the indication from the app and can automatically do service discovery again. 

Children
Related