<?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>Read value from several characteristics as central to a custom service</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86291/read-value-from-several-characteristics-as-central-to-a-custom-service</link><description>SDK 17.1.0 
 nRF52840 DK central + nRF52840 peripheral device 
 Hello, 
 I&amp;#39;m attempting to set up reading characteristic values on the nRF52840 DK as a central from a peripheral device which is a nRF52840 module with a SHT40 temperature and humidity sensor</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 30 Mar 2022 01:35:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86291/read-value-from-several-characteristics-as-central-to-a-custom-service" /><item><title>RE: Read value from several characteristics as central to a custom service</title><link>https://devzone.nordicsemi.com/thread/360635?ContentTypeID=1</link><pubDate>Wed, 30 Mar 2022 01:35:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b39e6319-6be7-45bd-9d5c-c38a03999167</guid><dc:creator>maxx44</dc:creator><description>&lt;p&gt;Thanks Susheel.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is somewhat helpful in that it tells me I have to resubmit the&amp;nbsp;sd_ble_gattc_char_value_by_uuid_read() function.&amp;nbsp; &amp;nbsp;However it doesn&amp;#39;t provide any details on how to implement the &amp;quot;updated handle range&amp;quot; in my code.&amp;nbsp; My best guess was to use routines like my code snippet above for each characteristic.&lt;/p&gt;
&lt;p&gt;This appears to be working.&amp;nbsp; I am able to read the characteristic values for all 3 of my custom service characteristics.&amp;nbsp; I implemented code to submit the&amp;nbsp;sd_ble_gattc_char_value_by_uuid_read() for each characteristic, then used a timer to check the response had been handled.&amp;nbsp; Then I launched the&amp;nbsp;sd_ble_gattc_char_value_by_uuid_read() for the next characteristic.&amp;nbsp; I can&amp;#39;t claim this is a &amp;quot;good&amp;quot; solution, just that it seems to work.&amp;nbsp; The SDK doesn&amp;#39;t appear to have examples cover the ble central function to the extent of the ble peripheral functions.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s what I have in the ble event handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
            {
              if (temp_read)
                {             
                  ble_gattc_handle_value_t iter;
                  memset(&amp;amp;iter, 0, sizeof(ble_gattc_handle_value_t));
                  while (sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(&amp;amp;p_ble_evt-&amp;gt;evt.gattc_evt, &amp;amp;iter) == NRF_SUCCESS)
                   {
                     memcpy(temp_value, iter.p_value, p_ble_evt-&amp;gt;evt.gattc_evt.params.char_val_by_uuid_read_rsp.value_len);
                   }
                   temp_read = false;
                }
              else if (hum_read)
                {             
                  ble_gattc_handle_value_t iter2;
                  memset(&amp;amp;iter2, 0, sizeof(ble_gattc_handle_value_t));
                  while (sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(&amp;amp;p_ble_evt-&amp;gt;evt.gattc_evt, &amp;amp;iter2) == NRF_SUCCESS)
                   {
                     memcpy(hum_value, iter2.p_value, p_ble_evt-&amp;gt;evt.gattc_evt.params.char_val_by_uuid_read_rsp.value_len);
                   }
                   hum_read = false;
                }
              else if (vbatt_read)
                {             
                  ble_gattc_handle_value_t iter3;
                  memset(&amp;amp;iter3, 0, sizeof(ble_gattc_handle_value_t));
                  while (sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(&amp;amp;p_ble_evt-&amp;gt;evt.gattc_evt, &amp;amp;iter3) == NRF_SUCCESS)
                   {
                     memcpy(vbatt_value, iter3.p_value, p_ble_evt-&amp;gt;evt.gattc_evt.params.char_val_by_uuid_read_rsp.value_len);
                   }
                   vbatt_read = false;
                }
              break;
            }
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As can be seen, I used some boolean semaphore&amp;#39;s to indicate a characteristic was handled and to move on to reading the next one.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s still a work in progress, but I&amp;#39;m good with this for now.&amp;nbsp; Hopefully this code might help someone grappling with the same problem despite the marginal coding style.&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;p&gt;Max&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Read value from several characteristics as central to a custom service</title><link>https://devzone.nordicsemi.com/thread/360475?ContentTypeID=1</link><pubDate>Tue, 29 Mar 2022 08:53:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05bf71a2-1da0-4101-99ac-023225074128</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;From the documentation of &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s140.api.v7.3.0%2Fgroup___b_l_e___g_a_t_t_c___f_u_n_c_t_i_o_n_s.html&amp;amp;cp=4_7_4_1_2_2_2_1&amp;amp;anchor=ga1e5d6f7c678b7db3205fa6b5c419f665"&gt;sd_ble_gattc_char_value_by_uuid_read&lt;/a&gt;, it shows that you need to call the function again with an updated handle range if there are more characteristics in this service that need to be read.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>