<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HOW to dynamically Change READ VALUES ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55717/how-to-dynamically-change-read-values</link><description>Hi ! 
 I added &amp;quot; Read Characteristic&amp;quot; in NUS. 
 
 How can I get different values every time I click &amp;quot;read again&amp;quot;? For example, read the value of a varying ADC from here. 
 How do I dynamically send an ADC value from here in NRF52832? Which API function</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 17 Dec 2019 09:58:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55717/how-to-dynamically-change-read-values" /><item><title>RE: HOW to dynamically Change READ VALUES ?</title><link>https://devzone.nordicsemi.com/thread/225838?ContentTypeID=1</link><pubDate>Tue, 17 Dec 2019 09:58:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6df0cccc-5153-4355-92fc-46c60aa61ddf</guid><dc:creator>cbd</dc:creator><description>&lt;p&gt;Your easiest way is to make have your NRF52832 update the characteristic value with your ADC data on a regular basis (say on a timer). There is no synchronisation between the read action on the phone app and the update of the data in the characteristic.&lt;/p&gt;
&lt;p&gt;If the phone app is set to allow notification events on the characteristic then you can set the notify bit when adding your characteristic definition (on the NRF52832) and trigger your app to automatically read the characteristic value by updating the characteristic with new ADC data and triggering a notification event on the NRF52832.&lt;/p&gt;
&lt;p&gt;Example of notification from some project code of mine:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint32_t lds_ResponseCharAdd(ble_lds_t * p_lds, const ble_lds_init_t * p_lds_init)
{
    if (NULL == p_lds)
    {
        return NRF_ERROR_INTERNAL;
    }
    ble_add_char_params_t add_char_params;


    memset(&amp;amp;add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid                     = LDS_UUID_RESPONSE_CHAR;
    add_char_params.uuid_type                = p_lds-&amp;gt;uuid_type;
    add_char_params.max_len                  = sizeof(lds_drive_data_t);
    add_char_params.init_len                 = sizeof(lds_drive_data_t);
    add_char_params.is_var_len               = true;
    add_char_params.char_props.notify        = 1;
    add_char_params.char_props.read          = 1;

    add_char_params.read_access  = SEC_OPEN;
    add_char_params.write_access = SEC_OPEN;
    add_char_params.cccd_write_access= SEC_OPEN;

    return characteristic_add(p_lds-&amp;gt;service_handle, &amp;amp;add_char_params, &amp;amp;p_lds-&amp;gt;lds_char_result_handles);

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;then when you want to update your ADC value you set the ble_gatts_hvx_params_t data with your data and update the characteristic using sd_ble_gatts_hvx and then sd_ble_gatts_value_set&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;e.g.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; /* set-up parameter data for BLE characteristic update notification */
    uint16_t len = data.dataLength + index; // sizeof(m_lds_result_data);
    ble_gatts_hvx_params_t params;

    memset(&amp;amp;params, 0, sizeof(params));
    params.type = BLE_GATT_HVX_NOTIFICATION;
    params.p_len = &amp;amp;len;

    /* update and notify for the characteristic */
    params.handle = m_LiveDriveService.lds_char_result_handles.value_handle;
    params.p_data = m_scratch_buffer;

    err_code = sd_ble_gatts_hvx(m_LiveDriveService.conn_handle, &amp;amp;params);
    if (NRF_SUCCESS != err_code)
    { /* notifications may not be enabled, attempt to update data */
        ble_gatts_value_t valueData;
        valueData.len = len;
        valueData.offset = 0;
        valueData.p_value = m_scratch_buffer;
        NRF_LOG_HEXDUMP_DEBUG(m_scratch_buffer, len);
        err_code = sd_ble_gatts_value_set(m_LiveDriveService.conn_handle,
                                          m_LiveDriveService.lds_char_result_handles.value_handle,
                                          &amp;amp;valueData);
        if (NRF_SUCCESS != err_code)
        {
            return err_code;
        }
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>