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

How to use Service Change in GATT server and GATT client

Hi all,

I have a trouble about understanding.

As far as I understand, when Device 1 send service change indication to Device 2, Device 2 will rediscovery service of Device 1 for update GATT table of Device 1.

When I test with Gatts_c example and GATTs, I can send Service change indication from service to client. And client will rediscovery service of Service in  NRF_BLE_GATTS_C_EVT_SRV_CHANGED event follow code : 

        case NRF_BLE_GATTS_C_EVT_SRV_CHANGED:
            NRF_LOG_INFO("Service Changed indication received.");
            NRF_LOG_INFO("Handle range start: %04x", p_evt->params.handle_range.start_handle);
            NRF_LOG_INFO("Handle range end: %04x", p_evt->params.handle_range.end_handle);
                            // Discover peer's services.
                                            err_code = nrf_ble_gatts_c_handles_assign(&m_gatts_c, p_evt->conn_handle, NULL);
                APP_ERROR_CHECK(err_code);
                memset(&m_ble_db_discovery, 0x00, sizeof(m_ble_db_discovery));
                err_code = ble_db_discovery_start(&m_ble_db_discovery, p_evt->conn_handle);
                APP_ERROR_CHECK(err_code);
            break;

And I want send service change indication from client to server. In gatts_c I enable service change characteristic in sdk_config.h . And in my code : 

      case BSP_EVENT_KEY_0:
      {
        sd_ble_gatts_service_changed (m_conn_handle,0x000C,0xFFFF);
      }

But I don't see anything at server side.

Then I using an Android connect with client GATT. My android find out service change characteristic. But when I push button 0, I don't see any changes on android.(I enabled service change characteristic on android. I think It will rediscovery service of client GATT.

Please show me a right view about service change characteristic

Thank!!!

  • Hi Giang, 

    Please check the error return code of sd_ble_gatts_service_changed() function. Make sure it's successful. 
    Also the CCCD to enable indication should be enabled (in your app it's enabled, but I'm not sure about the Device 2)

    Please be aware that on the phone Android/iOS, I don't think that the app would receive an event when the service changed indication is received. It's handled by the OS itself .

    I would suggest to use the sniffer trace to check if the indication is actually sent. 

  • Hi Hung Bui,

    I checked and this function return error 12291. But I don't know what is this error ? Can you solve it ?

    I hope you explain more carefully the use of the service change characteristic. As me know, You can use the characteristic change service in the DFU process. Please explain its purpose for me. I want to understand more about the service change characteristic and the circumstances in which to use it.

    Thank!!!

    
    
  • When you use a function, please have a look at the description of the function (in the .h file) to see how it work and which error code can be expected from that function. In this case the description is in ble_gatts.h. 

    The error code 12291 = 0x3003 = BLE_ERROR_INVALID_ATTR_HANDLE

    You need to use the handle range inside the range of handles you have in the attribute table. 

Related