This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Discovery service dosen't work always

When I keep this function :

static void vMain_iInitDeviceManager_Exe(bool erase_bonds)
{
    uint32_t               err_code;
    dm_init_param_t        init_param = {.clear_persistent_data = erase_bonds};
    dm_application_param_t register_param;

// Initialize persistent storage module.
err_code = pstorage_init();
APP_ERROR_CHECK(err_code);

err_code = dm_init(&init_param);
APP_ERROR_CHECK(err_code);

memset(&register_param.sec_param, 0, sizeof(ble_gap_sec_params_t));

register_param.sec_param.bond         = SEC_PARAM_BOND;
register_param.sec_param.mitm         = SEC_PARAM_MITM;
register_param.sec_param.lesc         = SEC_PARAM_LESC;
register_param.sec_param.keypress     = SEC_PARAM_KEYPRESS;
register_param.sec_param.io_caps      = SEC_PARAM_IO_CAPABILITIES;
register_param.sec_param.oob          = SEC_PARAM_OOB;
register_param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE;
register_param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE;
register_param.evt_handler            = device_manager_evt_handler;
register_param.service_type           = DM_PROTOCOL_CNTXT_GATT_SRVR_ID;

err_code = dm_register(&m_app_handle, &register_param);
APP_ERROR_CHECK(err_code);
}

the discovery service works, if not it dosen't work.

SDK11 , hrs_app image description

  • Hi,

    What do you see when discovery service doesn't work ? Which error ? Note that if you use pstorage you need to call pstorage_init(). If you remove vMain_iInitDeviceManager_Exe then the pstorage_init() is not called.

  • Yah , i do have pstorage init in other function when i comment this one. I edited my question, you can see the error in the image attached

  • If you don't use devicemanager, have you handled BLE_GATTS_EVT_SYS_ATTR_MISSING event ? This is needed in the case that the CCCD is not initialized. Usually you can call err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0); Please follow what we do in the ble_app_uart example.

    If you already handled that even could be that the device crashed, could you check if there if it still run after that ? If it didn't crash, could you tell which disconnected reason it is ? (inside DISCONNECTED event check for the reason inside p_ble_evt)

  • You are right, it is because of that. I find that that event is handled under the dm_manager event handler. So can you please tell me how can I avoid that? I mean , I should use sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0); in the main and it is ok ? or i have tohandle the event BLE_GATTS_EVT_SYS_ATTR_MISSING and call that function under it ?

  • Yes you have to "handle the event BLE_GATTS_EVT_SYS_ATTR_MISSING and call that function under it". But this is only applied if you don't store bond information and system attribute belong to that central. If you store bond information and want to re-init the system attribute (for example remember and automatically allow notification when the same central re-connect) you need to use the correct data instead of NULL. Other than that you can use NULL. Please look for BLE_GATTS_EVT_SYS_ATTR_MISSING event in the ble_app_uart to see how we handled it.

Related