<?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>Updating characteristic values while disconnected?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/26623/updating-characteristic-values-while-disconnected</link><description>I am developing an application as a peripheral based on the NRF52 SoC which regularly reads a sensor and publishes the reading to a BLE characteristic. A central (a smartphone app) connects to the NRF52 peripheral and immediately requests the current</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 Jul 2019 12:51:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/26623/updating-characteristic-values-while-disconnected" /><item><title>RE: Updating characteristic values while disconnected?</title><link>https://devzone.nordicsemi.com/thread/196266?ContentTypeID=1</link><pubDate>Wed, 03 Jul 2019 12:51:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4968872-2b62-4921-9c6a-c6415df79d17</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;I&amp;#39;ve just found this having had (almost) the same question.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial" rel="noopener noreferrer" target="_blank"&gt;Characteristics Tutorial&lt;/a&gt; is unhelpful, as it only covers doing notification - there is no help, guidance or even any mention of keeping the value updated while not connected.&lt;/p&gt;
&lt;p&gt;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;
[quote userid="2867" url="~/f/nordic-q-a/26623/updating-characteristic-values-while-disconnected/104749"]Yes you can call sd_ble_gatts_value_set with the default connection handle[/quote]
&lt;p&gt;Not just &amp;quot;&lt;em&gt;can&lt;/em&gt;&amp;quot; - you &lt;strong&gt;&lt;em&gt;must&lt;/em&gt;!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;&lt;span&gt;sd_ble_gatts_value_set documentation is misleading in this respect:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; * @param[in] conn_handle  Connection handle. Ignored if the value does not belong to a system attribute.&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It seems that it is not &lt;strong&gt;ignored&lt;/strong&gt; at all - it &lt;em&gt;&lt;strong&gt;must&lt;/strong&gt; &lt;/em&gt;be a valid connection handle.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating characteristic values while disconnected?</title><link>https://devzone.nordicsemi.com/thread/104749?ContentTypeID=1</link><pubDate>Mon, 06 Nov 2017 10:39:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf1d75be-947e-4ee3-9236-d6d9b222dc33</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I wouldn&amp;#39;t even bother with the else. Send HVX if there is a connection (need the if for that) but set the current value anyway so any new connection can read the initial value. It just keeps the current value in memory so anything initial connecting can read it.&lt;/p&gt;
&lt;p&gt;Yes you can call sd_ble_gatts_value_set with the default connection handle, it sets the value for the whole instance (I don&amp;#39;t think the change to multi peripheral altered that).&lt;/p&gt;
&lt;p&gt;and those are the right calls.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating characteristic values while disconnected?</title><link>https://devzone.nordicsemi.com/thread/104748?ContentTypeID=1</link><pubDate>Mon, 06 Nov 2017 10:34:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48f68084-4bf4-4760-9ab2-8924c45dbd6a</guid><dc:creator>jumpingfool</dc:creator><description>&lt;p&gt;Thanks for your feedback.&lt;/p&gt;
&lt;p&gt;Presumably sd_ble_gatts_value_set is used for this task? So I would replace my code as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if(peripheral-&amp;gt;conn_handle != BLE_CONN_HANDLE_INVALID) {
    hvx_params = [sensor reading]
    err_code = sd_ble_gatts_hvx(conn_handle, &amp;amp;hvx_params);
} else {
    p_value = [sensor reading]
    err_code = sd_ble_gatts_value_set(conn_handle, attr_handle, &amp;amp;p_value);
}
return err_code;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is that correct?&lt;/p&gt;
&lt;p&gt;Just noting that both functions require a connection handle - is it safe to call sd_ble_gatts_value_set when there is no valid connection?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating characteristic values while disconnected?</title><link>https://devzone.nordicsemi.com/thread/104747?ContentTypeID=1</link><pubDate>Mon, 06 Nov 2017 09:54:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1972e7b0-2b3e-4573-a758-16b743db9db6</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Very simple - as well as notifying the characteristic as you are doing, also keep the value of it up to date. When the client connects, as well as having it subscribe for notifications, also have it read the current value with a normal characteristic read. That&amp;#39;s all you have to do.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>