This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to stop a service then start another service?

Hi all, I want accive this situation. My peripheral connecting a central with a service for example hrs, then i stop the conect with the function sd_ble_gap_disconnect(m_conn_handle_peripheral, BLE_HCI_STATUS_CODE_SUCCESS). Then i want to stop the service and start a new service(bas for example), then i restart the new adveristing? How to remove a service then disconnect to a central then restart the new adv with a new service? Thanks~

  • Why do you want to do this exactly? You can add multiple services to your GATT table. Then you don't need to add and remove services from the table.

    When calling sd_ble_gap_disconnect(), you should provide the remote client terminated connection reason instead of the success reason: sd_ble_gap_disconnect(m_conn_handle_peripheral, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)

  • This can be achieved by restarting the softdevice.

    When sd_softdevice_disable is called, all memory used by the softdevice is freed. This includes the GATT database.

    After re-starting the softdevice, you can re-populate the GATT database with the new service. (Note that you also need to call sd_ble_enable to re-enable the BLE extension of the softdevice).

    To update the advertisement data, simply call sd_ble_gap_adv_data_set.

  • If you insist on changing the attribute table this is possible by disabling / re-enabling the softdevice. However note that some masters cache the attribute table so you will also need to send service changed indications. A better solution would normally be to populate the attribute table with all the services you need. The peer will have to subscribe to notificaitons/indications anyway...

Related