<?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>Writing a characteristic value from within the peripheral.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60183/writing-a-characteristic-value-from-within-the-peripheral</link><description>This is probably a simple question for an experienced nRF developer. 
 I have a demo going where I can read or write any of four characteristics I have set up on my peripheral (in my case an nRF58232 dev board) from the central. IE: I can easily use nRF</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 Apr 2020 14:04:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60183/writing-a-characteristic-value-from-within-the-peripheral" /><item><title>RE: Writing a characteristic value from within the peripheral.</title><link>https://devzone.nordicsemi.com/thread/246897?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2020 14:04:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c40769b-2060-4252-9ca8-0283c8fc8292</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply.&lt;/p&gt;
&lt;div&gt;For Question 1) What is the preferred call to update the characteristic value from within the peripheral itself?&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;If you only want to update the value, and not the send the update to a central, use &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v6.1.1%2Fgroup___b_l_e___g_a_t_t_s___f_u_n_c_t_i_o_n_s.html&amp;amp;anchor=ga2760c51ea71853bd74e2e7e7117ef52a"&gt;sd_ble_gatts_value_set&lt;/a&gt;().&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;For Question 2) What is the recommended code for sending this update back to the central?
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;Use sd_ble_gatts_hvx(), this will both update the internal characteristic value in the SD, and send the update to the central. See this Message Sequence chart on the infocenter: &lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v7.0.1%2Fgroup___b_l_e___g_a_t_t_s___h_v_n___m_s_c.html"&gt; https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v7.0.1%2Fgroup___b_l_e___g_a_t_t_s___h_v_n___m_s_c.html&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Best regards,&lt;/div&gt;
&lt;div&gt;Marjeris&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing a characteristic value from within the peripheral.</title><link>https://devzone.nordicsemi.com/thread/244823?ContentTypeID=1</link><pubDate>Wed, 15 Apr 2020 21:46:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c15d6d15-6560-4261-a81e-e5dc539db9c1</guid><dc:creator>TCdeveloper</dc:creator><description>&lt;p&gt;So I&amp;#39;ll partially answer my own question after a bit of exploration. By explicitly setting the handle of the characteristic I want to send to the central, I can easily communicate which characteristic got modified. The handle was retrieved and stored at the time I set up the characteristic using the call to:&amp;nbsp;&lt;span style="background-color:#ffffff;"&gt;sd_ble_gatts_characteristic_add&lt;/span&gt;();&lt;/p&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uint16_t&amp;nbsp; len = 1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ble_gatts_hvx_params_t hvx_params;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memset(&amp;amp;hvx_params, 0, sizeof(hvx_params));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hvx_params.handle = char_handle;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hvx_params.type&amp;nbsp;&amp;nbsp; = BLE_GATT_HVX_NOTIFICATION;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hvx_params.offset = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hvx_params.p_len&amp;nbsp; = &amp;amp;len;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hvx_params.p_data = (uint8_t*) char_value;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sd_ble_gatts_hvx(p_our_service-&amp;gt;conn_handle, &amp;amp;hvx_params);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="background-color:#ffffff;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;I now pass in the &amp;quot;char_handle&amp;quot; and &amp;quot;char_value&amp;quot; that I want to NOTIFY the central about.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;My question #1 still stands though on what is the preferred way to modify the characteristic at the peripheral. Currently, I am just directly modifying the location in memory (which is just a uint8_t variable) that I originally assigned to the characteristic value prior to initiation. However, I am still wondering if this might not be the best or proper way to inform the BLE stack that a value was changed.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Please advise. Thanks!&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>